jeudi 1 juin 2017

Exception with reflection and invoke

I have a problem since yesterday night, i got this exception :

java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.neferett.socket.events.ConnectEvent.lambda$runEvent$0(ConnectEvent.java:36)
at java.util.ArrayList.forEach(Unknown Source)
at net.neferett.socket.events.ConnectEvent.runEvent(ConnectEvent.java:34)
at net.neferett.socket.SockServer.lambda$null$1(SockServer.java:49)
at java.util.ArrayList.forEach(Unknown Source)
at net.neferett.socket.SockServer.lambda$buildThread$3(SockServer.java:49)
at java.lang.Thread.run(Unknown Source)

From:

@Override
public void runEvent(final Socket s, final Listener l) {
    this.s = s;
    final EventCaller ev = new EventCaller(l);

    final List<Method> m = ev.getMethodsByEvent(this.getClass());

    m.forEach(method -> {
        try {
            method.invoke(this, this);
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            e.printStackTrace();
        }

    });
}

I already looked all subjects about this exception but i don't find why it's not working,

The method that i invoke just take the instance of the class where runEvent is called.

Thanks for your help !





Aucun commentaire:

Enregistrer un commentaire