我的 Android 移动应用程序中很少有 NoClassDefFoundError 仅来自三星和 QMobile 的特定设备。
添加以下代码会检测到错误吗?
//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.
}
主动检测 NoClassDefFoundError 而不会导致应用程序崩溃的最佳方法是什么?
编辑:
文档说该方法引发了以下异常,并且没有提到任何关于NoClassDefFoundError
.
Throws:
LinkageError - if the linkage fails
ExceptionInInitializerError - if the initialization provoked by this method fails
ClassNotFoundException - if the class cannot be located
我可以改写这个问题
将
Class.forName(String)
抛出NoClassDefFoundError
或如何检查一个类是否有“Def”?