get Static Field Value - Android java.lang.reflect

Android examples for java.lang.reflect:Field Value

Description

get Static 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{
    public static Object getStaticFieldValue(Class cls, String fieldName) {
        Field fild = null;//w ww .  j  av  a  2  s  . c  o  m
        Object fildValue = null;
        try {
            fild = cls.getDeclaredField(fieldName);
            fild.setAccessible(true);
            fildValue = fild.get(null);
        } catch (NoSuchFieldException ex) {
            ExceptionHandler.processFatalException(ex);
        } catch (Exception ex) {
            ExceptionHandler.processFatalException(ex);
        }
        return fildValue;
    }
}

Related Tutorials