我的Android移动应用程序中只有来自三星和QMobile的特定设备的NoClassDefFoundError很少。
添加以下代码会检测错误吗?
//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的最佳方法是什么?
编辑:
documentation表示该方法会引发以下异常,并且未提及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"?
答案 0 :(得分:0)
我认为try-catch是处理异常的最佳方式(NoClassDefFoundError
本质上是什么)。
但处理导致这种情况发生的事情而不仅仅是遵守效果可能是明智的; NoClassDefFoundError
是一种效果,必须有一些东西可以阻止它突然冒出来。
如果您说它发生在图书馆内,那么您可以做两件事:
NoClassDefFoundError
通常标志着你遗漏了图书馆需要的东西;是对另一个图书馆的另一种依赖还是其他的东西。尝试深入了解图书馆的文档,你可能会想到它的一些东西。