I am working on a project that uses reflection to get the fields of a running Java application.
I managed to get the fields, but I cannot read or write them. This is an example that I found on the Internet:
Class aClass = MyObject.class Field field = aClass.getField("someField"); MyObject objectInstance = new MyObject(); Object value = field.get(objectInstance); field.set(objetInstance, value);
The problem is that I use the classes from the working jar file, and the classes that I'm trying to manipulate come from the Loader class. So instead of "MyObject.class" I have ".class". To get "MyObject", I tried using ClassLoader, but that didn't work.
If I just use ".class":
Object value = field.get(theLoadedClass);
I will get this error:
java.lang.IllegalArgumentException: Can not set int field myClass.field to java.lang.Class
Thanks.
source share