get Field Value - Android java.lang.reflect

Android examples for java.lang.reflect:Field Value

Description

get Field Value

Demo Code


import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main{
    /*  w ww  .jav  a 2  s.  com*/
    public static Object getFieldValue(Object object, String fieldName) {
        Class classType = object.getClass();
        Field fild = null;
        Object fildValue = null;
        try {
            fild = classType.getDeclaredField(fieldName);
            fild.setAccessible(true);
            fildValue = fild.get(object);

        } catch (NoSuchFieldException ex) {
          //  ExceptionHandler.processFatalException(ex);
        } catch (Exception ex) {
          //  ExceptionHandler.processFatalException(ex);
        }
        return fildValue;
    }
}

Related Tutorials