I’ve tried some things described in tutorial here: investigating a class’s methods. But when I tried to investigate the methods of android.content.SharedPreferences.Editor, I’ve got a ClassNotFoundException, cause Editor is actually an interface, not a class. So, how can I access methods of an interface using Java reflection? Thanks in advance.
Here is code:
String sClassName = "android.content.SharedPreferences.Editor";
try {
Class classToInvestigate = Class.forName(sClassName);
// Dynamically do stuff with this class
// List constructors, fields, methods, etc.
} catch (ClassNotFoundException e) {
// Class not found!
} catch (Exception e) {
// Unknown exception
}
You should be able to explore an interface in the same way as you would explore a class using reflection. The only difference beeing the fact that
isInterfacewill returntrue.Could you post some code and please precise if you are using JDK or Android SDK in your program as this could explain why you get a
ClassNotFoundException.Regards,
Stéphane