I have following class structure:
private static class MyStaticClass { public final String name; public final String photoUri; private MyStaticClass(String pName, String pPhotoUri) { this.name = pName; this.photoUri = pPhotoUri; } public static MyStaticClass getNewMyStaticClass(String pName) { return new MyStaticClass(pName, null); } } Now when I want to read the value of "name" and "photoUri" fields, it gives me "Object is not an instance of class". Following is the code:
void printValues() { try { Class cls = Class.forName("my.pkg.name.TestClass$MyStaticClass"); for(Field field: cls.getDeclaredFields()) { System.out.println("Field name: " + field.getName()); System.out.println("Field value: " + field.get(cls)); } } catch (Throwable e) { e.printStackTrace(); } } I also tried to pass "null" at field.get(null) to read the value but it gives null pointer exception.
Please help me, how can I read the value of the field "name" and "photoUri"?
TestClassfor clarity sake.