What's the problem in this code
import java.lang.reflect.*;
import java.awt.*;
class ABC
{
public Integer i;
ABC()
{
}
public void setInt(Integer t)
{
i = t;
}
}
public class SampleName {
public static void main(String[] args)
{
ABC g1 = new ABC();
g1.setInt(new Integer(10));
printFieldNames(g1);
}
static void printFieldNames(Object o) {
Class c = o.getClass();
Field[] publicFields = c.getDeclaredFields();
for (int i = 0; i < publicFields.length; i++)
{
try {
Object ref = publicFields.get(c);
System.out.println(" ref.toString() : " + ref.toString());
}catch(Exception e)
{
e.printStackTrace();
}
}
}
What is the problem with this code,at run time Iam getting this exception
java.lang.IllegalArgumentException: object is not an instance of declaring class
How can we get the value of field of an object

