修复NoClassDefFoundError的方法? [英] Approach for fixing NoClassDefFoundError?

查看:177
本文介绍了修复NoClassDefFoundError的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

NoClassDefFoundError - Eclipse和Android


我看到这个问题是在许多不同的背景下被问到很多。也许我们可以设置一些定位和修复策略?我很自私,所以我可以贡献的是恐怖故事和问题,对不起...



似乎这是在编译时可见的时候抛出的,但不是在运行时...如何发生?



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



在编译时静态绑定以避免问题是可能还是可取的? / p>

附加库的动态绑定如何在移动环境中工作?或者它必须绑定到我的.apk中,否则我需要安装? ...嗯,



建议非常感激。

解决方案


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


< blockquote>

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



在编译时静态绑定到
可以避免问题吗?


这是可能的,理想和必要的。



在Eclipse之外,您只需将您需要的JAR放在您的 libs / 中项目,用Ant编译,你完成了。



在Eclipse中,我学习成功的一种模式是将你需要的JAR放在<$ c您的项目中的$ c> libs / ,将它们作为JAR添加到构建路径(注意:不是外部JAR),并将其作为APK的一部分打包。请注意,我不是亲自使用Eclipse,所以我的经验是有限的。


Possible Duplicate:
NoClassDefFoundError - Eclipse and 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.

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.

Advice much appreciated.

解决方案

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.

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.

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.

这篇关于修复NoClassDefFoundError的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆