Java NoClassDefFoundError - Eclipse 和 Android
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2247998/
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 - Eclipse and Android
提问by Tom R
I'm having a problem trying to run an Android app which, up until adding a second external library to its build path, was working fine. Since having added the scoreninja jar, I now get a NoClassDefFoundErrorwhen I try to run the app.
我在尝试运行 Android 应用程序时遇到问题,该应用程序在向其构建路径添加第二个外部库之前一直运行良好。自从添加了 scoreninja jar 之后,当我尝试运行该应用程序时,我现在得到一个NoClassDefFoundError。
Here's the message:
这是消息:
02-11 21:45:26.154: ERROR/AndroidRuntime(3654): java.lang.NoClassDefFoundError: com.scoreninja.adapter.ScoreNinjaAdapter
As all of the build scripts are generated by the Android tools (?), I'm not sure what else I can do other than cleaning and rebuilding or restarting eclipse (I have already tried all three). Does anyone know how I can amend this?
由于所有构建脚本都是由 Android 工具 (?) 生成的,我不确定除了清理和重建或重新启动 eclipse 之外我还能做什么(我已经尝试了所有三个)。有谁知道我该如何修改?
回答by Anthony Forloney
By adding the external jar into your build path just adds the jar to your package, but it will not be available during runtime.
通过将外部 jar 添加到您的构建路径中,只会将 jar 添加到您的包中,但它在运行时将不可用。
In order for the jar to be available at runtime, you need to:
为了使 jar 在运行时可用,您需要:
- Put the jar under your
assets
folder - Include this copy of the jar in your build path
- Go to the export tab on the same popup window
- Check the box against the newly added jar
- 把罐子放在你的
assets
文件夹下 - 在构建路径中包含此 jar 副本
- 转到同一弹出窗口上的导出选项卡
- 选中新添加的 jar 对应的框
回答by Brian
I'm not sure if this is related, or if you're even still looking for an answer, but I came across this thread while trying to research the same error (but possibly for different reasons).
我不确定这是否相关,或者您是否仍在寻找答案,但是我在尝试研究相同的错误时遇到了这个线程(但可能出于不同的原因)。
I couldn't find any solutions online, but an answer on a similar thread got me thinking and realized I probably just needed to rebuild (or clean) the project.
我在网上找不到任何解决方案,但类似线程上的答案让我思考并意识到我可能只需要重建(或清理)项目。
In Eclipse, go to Project => Clean. Select your project and Eclipse seemed to fix it itself. For me this solved the problem.
在 Eclipse 中,转到 Project => Clean。选择您的项目,Eclipse 似乎会自行修复它。对我来说,这解决了问题。
Hope this helps.
希望这可以帮助。
回答by brian.clear
I had this for MapActivity. Builds in Eclipse gets NoClassDefFound in debugger.
我有这个用于 MapActivity。在 Eclipse 中构建在调试器中获得 NoClassDefFound。
Forgot to add library to manifest, inside <Application>...</Application>
element
忘记将库添加到清单,在<Application>...</Application>
元素内
<uses-library android:name="com.google.android.maps" />
回答by Andrew Krizhanovsky
I have changed the order of included projects (Eclipse / Configure Build Path / Order and Export). I have moved my two dependent projects to the top of the "Order and Export" list. It solved the problem "NoClassDefFoundError".
我更改了包含项目的顺序(Eclipse/配置构建路径/顺序和导出)。我已将我的两个相关项目移至“订购和导出”列表的顶部。它解决了“NoClassDefFoundError”问题。
It is strange for me. I didn't heard about the importance of the order of included libraries and projects. Android + Eclipse is fun :)
这对我来说很奇怪。我没有听说包含的库和项目的顺序的重要性。Android + Eclipse 很有趣 :)
回答by Wahib Ul Haq
I tried various things and the reason for error in my case was conflict between maps.jar and Google Api in Java Build Path-> Libraries. So, when i removed the maps.jar it worked fine.
我尝试了各种方法,在我的案例中出现错误的原因是 Java Build Path-> Libraries 中的 maps.jar 和 Google Api 之间的冲突。所以,当我删除 maps.jar 时它工作正常。
Regards,
问候,
wahib
瓦希卜
回答by John O'Connor
I had this problem after updating ADT.
更新 ADT 后我遇到了这个问题。
I was storing all of my JAR files in a folder called "lib" and adding the jars to the build path the normal Eclipse way. This worked fine until my update.
我将所有 JAR 文件存储在一个名为“lib”的文件夹中,并以正常的 Eclipse 方式将 jar 添加到构建路径中。这工作正常,直到我更新。
After my update, I was getting the NoClassDefFoundError for a class that I could clearly see was included in the jar (checking out the ReferencedLibraries classes).
更新后,我得到了一个类的 NoClassDefFoundError,我可以清楚地看到包含在 jar 中的类(查看 ReferencedLibraries 类)。
The solution was to remove my jars from the build path and rename my "lib" folder to "libs". This is an ant convention, and seems to be the way the new ADT finds and includes libraries in an .apk file. Once I did this, everything worked fine.
解决方案是从构建路径中删除我的 jars 并将我的“lib”文件夹重命名为“libs”。这是一个 ant 约定,似乎是新 ADT 在 .apk 文件中查找和包含库的方式。一旦我这样做了,一切都很好。
回答by Till
I didn't have to put the jar-library in assets or lib(s), but only tick the box for this jar in Properties -> Java Build Path -> "Order and Export" (it was listed before, but not selected)
我不必将 jar-library 放在 assets 或 lib(s) 中,而只需在 Properties -> Java Build Path -> "Order and Export" 中勾选此 jar 的框(之前已列出,但未选中) )
回答by vlad
Same thing worked for me: Properties -> Java Build Path -> "Order and Export" Interestingly - why this is not done automatically? I guess some setting is missing. Also this happened for me after SDK upgrade.
同样的事情对我有用:属性 -> Java 构建路径 -> “订购和导出” 有趣的是 - 为什么这不是自动完成的?我想缺少某些设置。SDK升级后这也发生在我身上。
回答by zacharia
Right click your project folder, look for Properties in Java build path and select the jar files that you see. It has worked for me.
右键单击您的项目文件夹,在 Java 构建路径中查找 Properties 并选择您看到的 jar 文件。它对我有用。
回答by assylias
I have encountered the same issue. The reason was that the library that I was trying to use had been compiled with a standard JDK 7.
我遇到了同样的问题。原因是我尝试使用的库是使用标准 JDK 7 编译的。
I recompiled it with the -source 1.6 -target 1.6
options and it worked fine.
我用-source 1.6 -target 1.6
选项重新编译它,它工作正常。