Hi,
I would like to know how to read non-static Fields via Reflection in Java when using the URLClassloader to create a new Instance rather then just creating an object and use Reflection on it. This is all related to Reflection in Runescape.
- I have successfully loaded Runescape into my own JFrame via URLClassloader.
- I have a source for the Hooks which i downloaded, so i know which classes i have to load from the runescape-jar and what the fieldnames are and what values i get from them
- I have implement (more or less copied it :P) a class which uses Reflection to read Field values
Everything works fine for static fields since you dont need an object-instance/reference for reading those fields.
But for non-static fields object-instance/reference is necessary.
Currently iam using the created applet-instance of the Runescape client class as object-reference.
Code:
Applet applet = (Applet) reflector.loadClass(getParameter("initial_class").replaceAll(".class", "")).newInstance();
applet.setStub(this);
applet.init();
applet.start();
applet.setPreferredSize(new Dimension(765, 503));
But this is not working.
Code:
java.lang.IllegalArgumentException: Can not set java.lang.String field z.i to client
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(Unknown Source)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(Unknown Source)
at java.lang.reflect.Field.get(Unknown Source)
I need an object-instance/reference for the class z if iam understanding this correct. But how would i get this object-instance/reference out of the applet-instance?
Field z.i should return the Players name by the way.
Here is the Reflector source code (Line 33 produces the error)
http://pastebin.com/iJJakGHE
If the problem is not clear enough ( bad english ), feel free to ask questions and i will try to explain further more.