jeudi 5 février 2015

TypeNotPresentException thrown when reflecting on a method

I've got a sub class that has a method that throws an exception in an Android project.



public class Bar extends Foo {
public void method(String someClass) throws ReflectiveOperationException {
Class.forName(someClass);
}
}


I've got a base class with a method that reflects on its own methods which, of course, can be called from the subclass.



public class Foo {
public void reflectOnMethods() {
for (Method m : this.getClass().getDeclaredMethods()) {
//do stuff with methods
}
}
}


And when Bar calls its inherited reflectOnMethods, I'm presented with a stack trace like so



02-05 21:58:04.461: E/AndroidRuntime(2737): java.lang.TypeNotPresentException: Type java/lang/ReflectiveOperationException not present
02-05 21:58:04.461: E/AndroidRuntime(2737): at java.lang.Class.getDeclaredMethods(Native Method)
02-05 21:58:04.461: E/AndroidRuntime(2737): at java.lang.Class.getDeclaredMethods(Class.java:703)


The issue goes away when I change the thrown exception from ReflectiveOperationException to ClassNotFoundException but WHY IS THAT THE FIX??!!?


I'm puzzled by it and would look into the JDK source to try to figure it out but I'm feeling lazy.






Aucun commentaire:

Enregistrer un commentaire