Android NoClassDefFoundError - 拒绝在先前失败的类上重新初始化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12696561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NoClassDefFoundError - Rejecting re-init on previously-failed class
提问by bartat
Please somebody explain me what this error means and how to avoid it.
请有人向我解释这个错误的含义以及如何避免它。
After a while my app Force Closes because of this error:
一段时间后,由于此错误,我的应用程序强制关闭:
09-28 12:53:45.746 I/dalvikvm(29489): Rejecting re-init on previously-failed class Lcom/bartat/android/ui/task/AsyncTaskExt; v=0x0
09-28 12:53:45.748 D/AndroidRuntime(29489): Shutting down VM
09-28 12:53:45.755 I/am_crash( 1146): [29489,com.bartat.android.secret,572996,java.lang.NoClassDefFoundError,com.bartat.android.ui.task.AsyncTaskExt,CommandsActivity.java,726]
09-28 12:53:45.755 I/am_finish_activity( 1146): [1079225264,123,com.bartat.android.secret/.CommandsActivity,crashed]
09-28 12:53:45.750 W/dalvikvm(29489): threadid=1: thread exiting with uncaught exception (group=0x40015560)
09-28 12:53:45.752 E/AndroidRuntime(29489): FATAL EXCEPTION: main
09-28 12:53:45.752 E/AndroidRuntime(29489): java.lang.NoClassDefFoundError: com.bartat.android.ui.task.AsyncTaskExt
This problem couldn't be solved by reinstalling the app.
重新安装应用程序无法解决此问题。
If I rename the AsyncTaskExt
to AsyncTaskExt2
for example then it works again for long. But after a few weeks/months it started to get this error again.
如果我重新命名AsyncTaskExt
,以AsyncTaskExt2
例如然后再工作很长时间。但几周/几个月后,它又开始出现这个错误。
What does it mean? Why it is thrown and how to avoid it without renaming the class?
这是什么意思?为什么会抛出它以及如何在不重命名类的情况下避免它?
Please help me, Tamás
请帮帮我,塔玛斯
回答by Tobias
Happens for me only if instant runis enabled.
仅当启用即时运行时才会发生在我身上。
回答by Combuster
This happens when a class couldn't be loaded for a variety of reasons. Unfortunately the new ART runtime doesn't log sufficient information as to the cause of this. If you can get hold of an older android device with Dalvik you'll see different logging, usually revealing the offence with more precision.
当由于各种原因无法加载类时会发生这种情况。不幸的是,新的 ART 运行时没有记录关于此原因的足够信息。如果您可以使用 Dalvik 获取较旧的 android 设备,您会看到不同的日志记录,通常会更准确地揭示进攻。
Last time I saw it live I had to deal with a JAR file that didn't actually include or list its dependencies, so adding the right dependent library to the gradle file solved it. The biggest issue is to figure which classes went missing - something dalvik logs/decompilation/documentation might be able to tell you.
上次我看到它直播时,我不得不处理一个实际上并未包含或列出其依赖项的 JAR 文件,因此将正确的依赖库添加到 gradle 文件中解决了这个问题。最大的问题是找出哪些类丢失了——dalvik 日志/反编译/文档可能会告诉你一些东西。
There are many other reasons why classes can't be loaded in the entirety of the Java language so this specific cause might not apply universally.
无法在整个 Java 语言中加载类还有许多其他原因,因此这个特定原因可能并不普遍适用。
回答by Pavel Synek
I started having this problem after building another project with New Relic analytics enabled. Gradle daemon then cached the New Relic agent and it couldn't launch the other app.
在构建另一个启用了 New Relic 分析的项目后,我开始遇到这个问题。Gradle 守护进程随后缓存了 New Relic 代理,并且无法启动其他应用程序。
What helped was
有什么帮助
./gradlew --stop
回答by laowen
you must add uses-library in your AndroidManifest.xml
您必须在 AndroidManifest.xml 中添加 uses-library
回答by Durairaj Packirisamy
Are you sure is this the first exception you are getting after running your application? There may be some uncaught exceptions previously.
您确定这是运行应用程序后遇到的第一个异常吗?之前可能有一些未捕获的异常。