Android examples for java.lang.reflect:Field Value
get Int Field Value
import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main{ public final static int INVALID_VALUE = -1; // w w w . ja v a 2 s. c om public static int getIntFieldValue(Object object, String filedName) { Class classType = object.getClass(); Field fild = null; int fildValue = INVALID_VALUE; try { fild = classType.getDeclaredField(filedName); fild.setAccessible(true); fildValue = fild.getInt(object); } catch (NoSuchFieldException ex) { // ExceptionHandler.processFatalException(ex); } catch (Exception ex) { // ExceptionHandler.processFatalException(ex); } return fildValue; } }