jeudi 5 février 2015

TypeNotPresentException thrown when reflecting on a method


Vote count:

0




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() throws ReflectiveOperationException {
//reflect on stuff
}
}


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.



asked 1 min ago

Kairos

635






TypeNotPresentException thrown when reflecting on a method

Aucun commentaire:

Enregistrer un commentaire