How to fix NoClassDefFoundError in AndroidRuntime Error? [duplicate]

社会主义新天地 提交于 2020-01-19 18:07:49

问题


I'm working on a github android project: ebookdroid. I import the code in eclipse, I select the NDK path for compile the c and cpp files. Once finished there are no errors. I run project on my device and in the log there is java.lang.NoClassDefFoundError.

06-14 11:25:57.806: E/AndroidRuntime(16523): FATAL EXCEPTION: main
06-14 11:25:57.806: E/AndroidRuntime(16523): java.lang.NoClassDefFoundError: org.ebookdroid.ui.library.adapters.BooksAdapter
06-14 11:25:57.806: E/AndroidRuntime(16523):    at org.ebookdroid.ui.library.RecentActivityController.beforeCreate(RecentActivityController.java:104)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at org.ebookdroid.ui.library.RecentActivityController.beforeCreate(RecentActivityController.java:1)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at org.emdev.ui.AbstractActionActivity.onCreate(AbstractActionActivity.java:93)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at android.app.Activity.performCreate(Activity.java:4469)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at android.os.Looper.loop(Looper.java:137)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at android.app.ActivityThread.main(ActivityThread.java:4507)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at java.lang.reflect.Method.invokeNative(Native Method)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at java.lang.reflect.Method.invoke(Method.java:511)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:978)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
06-14 11:25:57.806: E/AndroidRuntime(16523):    at dalvik.system.NativeStart.main(Native Method)
06-14 11:32:40.056: I/Process(16613): Sending signal. PID: 16613 SIG: 9

Why this error? In the class I import the right package of BooksAdapter... Someone can tell me what can I try? Sorry for my bad english & Thank you in advance!


回答1:


Since you are using an library, and this is runtime exception. So just go to the

Project Properties>Java Build Path>Order and Import tab and check the libraries you are using.

It seems that ADT update 22, you have to do this manually: Libraries do not get added to APK anymore after upgrade to ADT 22




回答2:


The reason of NoClassDefFoundError is that a particular class is not available in Classpath, so we need to add that into Classpath or we need to check why it’s not available in Classpath if we are expecting it to be. There could be multiple reasons like:

1) Class is not available in Java Classpath.

2) You might be running your program using jar command and class was not defined in manifest file's ClassPath attribute.

3) Any start-up script is overriding Classpath environment variable.

4) Because NoClassDefFoundError is a sub class of java.lang.LinkageError it can also come if one of it dependency like native library may not available.

5) Check for java.lang.ExceptionInInitializerError in your log file. NoClassDefFoundError due to failure of static initialization is quite common.

6) If you are working in Java EE environment than visibility of Class among multiple Classloaders can also cause java.lang.NoClassDefFoundError, see examples and scenario section for detailed discussion.

We will now see couple of example and scenarios when java.lang.NoClassDefFoundError has came before and how its been resolved. This can help you to troubleshoot root cause of NoClassDefFoundError in Java application.



来源:https://stackoverflow.com/questions/17105995/how-to-fix-noclassdeffounderror-in-androidruntime-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!