vendredi 30 juin 2017

Invoking a static method with java reflection library

I am trying to invoke the following static method through the java reflection library.

import java.net.InetAddress;
import java.net.UnknownHostException;

public class ah
{
  static void a()
  {
    try
    {
      Client.dU = 10;
      Client.dV = 0;
      Client.dX = true;
      cp.d = 32;
      cp.a(InetAddress.getLocalHost());
      Client.iq = Client.E();
      Client.ir = w.a();
      Client.is = 2019030189;
    }
    catch (UnknownHostException localUnknownHostException) {}
  }
}

My current code is as follows

public void invokeInit() throws NoSuchMethodException, SecurityException, IllegalAccessException,
            IllegalArgumentException, InvocationTargetException {
        Class<?> initClass = loader.loadClass("ah");
        Method initMethod = initClass.getDeclaredMethod("a", null);
        initMethod.invoke(null, new Object[] {});
    }

It gives me the following error

java.lang.IllegalAccessException: Class org.baiocchi.client.reflection.Game can not access a member of class ah with modifiers "static"
    at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
    at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296)
    at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288)
    at java.lang.reflect.Method.invoke(Method.java:491)
    at org.baiocchi.client.reflection.Game.invokeInit(Game.java:28)
    at org.baiocchi.client.reflection.Game.getApplet(Game.java:33)
    at org.baiocchi.client.Engine.start(Engine.java:21)
    at org.baiocchi.client.Booter.main(Booter.java:6)

Thank you in advance for any help!





Aucun commentaire:

Enregistrer un commentaire