eclipse 修复 NoClassDefFoundError 的方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2456562/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:31:07  来源:igfitidea点击:

Approach for fixing NoClassDefFoundError?

javaandroideclipsegdata-apinoclassdeffounderror

提问by DJC

Possible Duplicate:
NoClassDefFoundError - Eclipse and Android

可能重复:
NoClassDefFoundError - Eclipse 和 Android

I'm seeing this question is getting asked a lot in many different contexts. Perhaps we can set some strategies for locating and fixing it? I'm noobish myself so all I can contribute are horror stories and questions, sorry...

我看到这个问题在许多不同的情况下被问到很多。也许我们可以制定一些策略来定位和修复它?我自己是菜鸟,所以我只能贡献恐怖故事和问题,对不起...

It seems this is thrown when a class is visible at compile time but not at run time... how can this happen?

当一个类在编译时可见但在运行时不可见时,似乎会抛出这个......这怎么会发生?

In my case I am developing an app that uses the Google APIs, in Eclipse, for the Android platform. I've configured the Project Properties / Java Build Path / Libraries to include the gdata .jars and all is well. When I execute in the emulator I get a force close and the logcat shows a NoClassDefFoundError on a simple new ContactsService("myApp"); I've also tried a new CalendarService("myApp") with the same results.

就我而言,我正在开发一个应用程序,该应用程序在 Eclipse 中为 Android 平台使用 Google API。我已经配置了项目属性/Java 构建路径/库以包含 gdata .jars,一切都很好。当我在模拟器中执行时,我强制关闭并且 logcat 在一个简单的 new ContactsService("myApp"); 上显示 NoClassDefFoundError; 我还尝试了一个新的 CalendarService("myApp") ,结果相同。

Is it possible or desirable to statically bind at compile time to avoid the problem?

是否可以或希望在编译时静态绑定以避免该问题?

How could dynamic binding of an add-on library work in the mobile environment anyway? Either it has to be bound into my .apk or else I need to "install" it? ... hmmm.

无论如何,附加库的动态绑定如何在移动环境中工作?要么它必须绑定到我的 .apk 中,要么我需要“安装”它?……嗯。

Advice much appreciated.

非常感谢您的建议。

回答by CommonsWare

It seems this is thrown when a class is visible at compile time but not at run time... how can this happen?

当一个类在编译时可见但在运行时不可见时,似乎会抛出这个......这怎么会发生?

The build classpath may include JARs that are not being packaged into the APK.

构建类路径可能包含未打包到 APK 中的 JAR。

Is it possible or desirable to statically bind at compile time to avoid the problem?

是否可以或希望在编译时静态绑定以避免该问题?

It is possible, desirable, and necessary.

这是可能的、可取的和必要的。

Outside of Eclipse, you just put the JARs you need in libs/in your project, compile with Ant, and you are done.

在 Eclipse 之外,您只需将您需要的 JAR 文件libs/放入您的项目中,使用 Ant 进行编译,您就大功告成了。

Inside of Eclipse, one pattern I have had students use with success is to put the JARs you need in libs/in your project, add them as JARs to the build path (note: not external JARs), and they get packaged as part of the APK. Note, though, that I do not personally use Eclipse, and so my experience with it is limited.

在 Eclipse 内部,我让学生成功使用的一种模式是将您需要的 JAR 放入libs/项目中,将它们作为 JAR 添加到构建路径中(注意:不是外部 JAR),然后将它们打包为 APK 的一部分. 但请注意,我个人并不使用 Eclipse,因此我的经验有限。

回答by user1215183

For those having problem I was having the same error with my app. what I did to solve that was create a new project and copy my resource and source folders along with my manifest file into the new project (I deleted in advance those within the new project created) and voila.

对于那些有问题的人,我的应用程序也有同样的错误。我为解决这个问题所做的是创建一个新项目并将我的资源和源文件夹以及我的清单文件复制到新项目中(我预先删除了创建的新项目中的那些),瞧。

回答by Zds

When I got this, the problem was actually deeper in the queue; Dalvik converter had failed to convert some of the referenced libraries and still Eclipse allowed me to launch the project.

当我得到这个时,问题实际上在队列中更深;Dalvik 转换器未能转换一些引用的库,但 Eclipse 仍然允许我启动该项目。

Check the Android SDK console to see if there are any errors reported.

检查 Android SDK 控制台以查看是否报告了任何错误。

回答by Richard Le Mesurier

In my case, I'm using my own library (MyLib) shared between 2 apps. App A was closed when I added a new class to the library.

就我而言,我使用的是在 2 个应用程序之间共享的我自己的库 (MyLib)。当我向库中添加一个新类时,App A 已关闭。

When I opened App A to work on it, Eclipse recognised the new class, and I was able to reference it. However on running I got the error.

当我打开 App A 来处理它时,Eclipse 识别出这个新类,并且我能够引用它。但是在运行时我得到了错误。

It turned out that the imported library folder in App A (named something like MyLib_src) didn't reflect the changes made to my library project (MyLib).

结果证明,App A 中导入的库文件夹(命名为 MyLib_src)并没有反映对我的库项目 (MyLib) 所做的更改。

  • To solve this I refreshed App A, the changes reflected, and Android could build my project correctly.
  • 为了解决这个问题,我刷新了 App A,反映了更改,Android 可以正确构建我的项目。

I have found no reference to this version of the problem, so thought I would add it to this list.

我没有发现这个版本的问题的参考,所以我想我会把它添加到这个列表中。