modify Field Value - Android java.lang.reflect

Android examples for java.lang.reflect:Field Value

Description

modify 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 w  w.j a v a 2  s. com
    public static void modifyFieldValue(Object object, String filedName,
            String filedValue) {
        Class classType = object.getClass();
        Field fild = null;
        try {
            fild = classType.getDeclaredField(filedName);
            fild.setAccessible(true);
            fild.set(object, filedValue);
        } catch (NoSuchFieldException ex) {
           // ExceptionHandler.processFatalException(ex);
        } catch (Exception ex) {
           // ExceptionHandler.processFatalException(ex);
        }
    }
}

Related Tutorials