I am getting few NoClassDefFoundError in my Android mobile app only from specific devices of Samsung and QMobile.
Will adding the below code detect the error?
//Check for Class not found error for Samsung 4.2.2 devices case
try {
Class.forName("android.support.v7.internal.view.menu.MenuBuilder");
} catch (ClassNotFoundException e) {
// Handle Exception by displaying an alert to user to update device firmware.
}catch (NoClassDefFoundError e){
// Handle Exception by displaying an alert to user to update device firmware.
}
What is the best way to detect a NoClassDefFoundError proactively without ending up in app crash?
Edit:
The documentation says that the method throws the below exceptions and it does not mentions anything about NoClassDefFoundError
.
Throws:
LinkageError - if the linkage fails
ExceptionInInitializerError - if the initialization provoked by this method fails
ClassNotFoundException - if the class cannot be located
I can rephrase the question like
Will
Class.forName(String)
throwNoClassDefFoundError
or How can I check if a class has a "Def"?