get Private Field - Android java.lang.reflect

Android examples for java.lang.reflect:Field Private

Description

get Private Field

Demo Code


//package com.java2s;
import java.lang.reflect.Field;

import android.util.Log;

public class Main {
    public static final String TAG = "ReflectionHelper";

    public static Object getPrivateField(String canonicalClassName,
            String fieldName, Object o) {
        try {//from ww  w . j  ava 2 s.com
            Class<?> viewObj = Class.forName(canonicalClassName);
            Field field = viewObj.getDeclaredField(fieldName);
            field.setAccessible(true);
            return field.get(o);
        } catch (Exception ex) {
            Log.e(TAG, ex.toString());
        }

        return null;
    }
}

Related Tutorials