lundi 21 mars 2016

NullPointer when using reflection to invoke a static method

I am trying to invoke a private static method declared in a Class .

Method method = Class.getDeclaredMethod("isResourcePotentiallyOnPath" , new Class[]{String.class, List.class});

method.setAccessible(true);

and then,

Object [] args = new Object[2];
args[0] = "SomeResource"
args[1] = null; //by default i want to pass in null here

boolean returnValue = (Boolean)method.invoke(null, args);

I see that method is not null but method.invoke causing null pointer somewhere down the stack

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)

What am i doing wrong??

Thanks





Aucun commentaire:

Enregistrer un commentaire