vendredi 17 avril 2015

Class getDeclaredMethods() returns an empty array

I'm creating an Android app that needs to load a class at runtime through reflection. I'm able to load the class, but when I call getDeclaredMethods() it returns an empty array. The class is not void, or null, or an array/List. It's just a POJO.



Class<?> crashManagerClass = Class.forName("net.hockeyapp.android.CrashManager");

crashManagerClass.getDeclaredMethods(); //<< empty array

CrashManager cmInstance = ((CrashManager)crashManagerClass.newInstance());

boolean isNull = cmInstance == null; // false
boolean isInstanceCM = cmInstance instanceof CrashManager; // true

cmInstance.register(context, "1234", listener); //<< throws exception

Method registerMethod = crashManagerClass.getDeclaredMethod("register", Context.class, String.class, listenerClass);
/* throws NoSuchMethodException */


I tried the same process on other library classes, and they work fine. Is it possible the library is corrupted somehow?


The class will load normally if instantiated the regular way.


The library is the HockeyApp SDK.






Aucun commentaire:

Enregistrer un commentaire