Search code examples
javaandroidclassloadernosuchmethoderror

DexClassLoader - invoke method with parameter


I have met some tutorials on the web, which are invoking simple methods and all I need is to invoke method "startDownload" which accepts Context as a parameter. I am now calling it:

Class<?> loaded = cl.loadClass("com.test.someclass");
Method m = loaded.getDeclaredMethod("startDownload", null);
m.invoke(this, null); 

where c1 is DexClassLoader. But no success. I am getting error of NoSuchMethodException, I know I have to add parametres somewhere, but don't know where... any advices?

Thanks


Solution

  • I suggest looking at that post.

    The parameters are passed after the method name when calling Class.getMethod(name, ...), as described here. You can directly use the class member of the Class you have to pass:

    Method myMethod = myClass.getMethod("doSomethingWithAString", String.class);
    

    Maybe you forgot some of them: the method won't be found if the signature (so the parameters) are not correct.