I want to get the value a class attribute, But I am getting exception : java.lang.NoSuchFieldException
Person.class
public class Person { public static final String name = "person name"; } MainActivity.class
... private void method() { Class myClass = Person.class; String name = myClass.getField("name"); } ... I am getting a java.lang.NoSuchFieldException exception for the getField method.
I tried these solutions but with no avail ...
Change getField method to getDeclaredField
Surround the code by try/catch, and got another error (Incompatible types : java.lang.String and java.lang.reflect.Field)
Invalidate Android Studio caches and restart
I don't Know how to access this value, Any solutions or suggestions are welcomed.
Thanks in advance.