gpt4 book ai didi

java - 如何检查NoClassDefFoundError?

转载 作者:太空宇宙 更新时间:2023-11-04 12:50:46 25 4
gpt4 key购买 nike

我的 Android 移动应用程序中仅从 Samsung 和 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 而不会导致应用程序崩溃的最佳方法是什么?

Edit:

documentation表示该方法抛出以下异常,并且没有提及任何有关 NoClassDefFoundError 的内容。

Throws:
LinkageError - if the linkage fails
ExceptionInInitializerError - if the initialization provoked by this method fails
ClassNotFoundException - if the class cannot be located

我可以重新表述这个问题

Will Class.forName(String)throw NoClassDefFoundError or How can I check if a class has a "Def"?

最佳答案

我认为,try-catch 是处理异常的最佳方法(本质上就是 NoClassDefFoundError )。

但是处理导致这种情况发生的事情而不是仅仅遵守效果可能是明智的; NoClassDefFoundError 是一种效果,您必须采取一些措施来防止它弹出。

如果正如您所说,它发生在图书馆内,那么您可以做两件事:

  • 向维护者报告(如果您认为这确实是他们的错误),或者
  • 尝试解决原因而不是结果(异常(exception))。 NoClassDefFoundError 通常标志着您缺少库需要的东西;无论是对另一个库的依赖还是其他东西。

尝试深入挖掘库的文档,您可能会从中找到一些东西。

关于java - 如何检查NoClassDefFoundError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35865369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com