get Field Value via reflection - Android java.lang.reflect

Android examples for java.lang.reflect:Field Value

Description

get Field Value via reflection

Demo Code


import java.lang.reflect.Field;
import java.lang.reflect.Method;
import android.util.Log;

public class Main{
    private static final String TAG = "";
    public static Object getFieldValue(Class<?> fieldClass,
            String fieldName, Object instance) {
        try {/*from   w ww .ja  v a 2s  . c om*/
            final Field field = fieldClass.getDeclaredField(fieldName);
            field.setAccessible(true);
            return field.get(instance);
        } catch (Exception e) {
            Log.w(TAG, Log.getStackTraceString(e));
        }
        return null;
    }
}

Related Tutorials