NoClassDefFoundError,这里忽略了什么? (附图)

时间:2012-05-30 16:22:57

标签: java android adt noclassdeffounderror

症状:我正在使用我从创建者的git存储库中提取的项目。我包含了他们的库,如libs文件夹中所示。项目没有错误,项目编译。然而,当它访问应该在jar中的对象时,它会崩溃。

我已经做了一些我在这里读过的其他建议。我已经阅读了有关更改classpath的内容,这是哪个?

此外,jar的src代码显示有问题的对象实际存在....

ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

05-30 11:26:16.878: E/AndroidRuntime(11098): FATAL EXCEPTION: main
05-30 11:26:16.878: E/AndroidRuntime(11098): java.lang.NoClassDefFoundError:      twitter4j.conf.ConfigurationBuilder
05-30 11:26:16.878: E/AndroidRuntime(11098):    at com.pigmal.android.ex.twitter4j.TwitterApp.askOAuth(TwitterApp.java:110)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at com.pigmal.android.ex.twitter4j.TwitterApp.onClick(TwitterApp.java:144)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at android.view.View.performClick(View.java:2482)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at android.view.View$PerformClick.run(View.java:9077)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at android.os.Handler.handleCallback(Handler.java:587)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at a ndroid.os.Handler.dispatchMessage(Handler.java:92)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at android.os.Looper.loop(Looper.java:130)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at android.app.ActivityThread.main(ActivityThread.java:3683)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at java.lang.reflect.Method.invokeNative(Native Method)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at java.lang.reflect.Method.invoke(Method.java:507)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at dalvik.system.NativeStart.main(Native Method)

这是我完整的项目设置。这是使用Android的事实可能与此无关,我不想通过标记Android来疏远Java专家

http://i46.tinypic.com/2s0lj5y.png

5 个答案:

答案 0 :(得分:4)

这为我解决了http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17

What I did to fix the bug was :

Remove the libraries from the standard Java build path :
Right click on the project name > Properties > Java Build Path > tab Libraries > remove      everything except the “Android X.X” (2.3.3 in my case) and the “Android Dependencies”
Rename the libraries folder from “lib” to “libs”
By doing that, all the libraries in the folder “libs” are found by the Android plugin and   are added to the “Android Dependencies” item of the project
Restart Eclipse
Android Dependencies should be created. Running the app won't produce NoClassDefFoundError anymore

除了我遵循这些说明后不得不重新启动ECLIPSE,而不仅仅是之后清理项目。

答案 1 :(得分:2)

试试这个,这对我有用。

  1. 转到Build Path,删除twitter4j库,然后执行Ok。

  2. 转到Build Path,选择Add External Libraries,然后转到你从github下载的项目文件夹,然后转到它的lib文件夹,你会在那里找到twitter4j文件,选择twitter4j-仅核心(但仅限于且仅当它仍然失败时包括twitter4j-stream,直到那时只保留核心)并且做好。

答案 2 :(得分:1)

我遇到了同样的问题,从构建路径中删除所有twitter库并将lib文件夹重命名为libs解决了我的问题

答案 3 :(得分:0)

我认为你最好用这个问题标记android。我见过早期帖子上的人有类似的问题,即使是因为ADT版本。理想情况下,由于您已将代码放在libs文件夹中,因此您应该能够获得所有这些类。但这似乎是一些运行时问题,而不是编译时间。

此外,这似乎是特定于android。


您是否在classpath中手动添加了jar? 通常,当在libs文件夹中添加jar时,它会开始显示在Android Dependencies内,而不是直接显示在快照中。

答案 4 :(得分:0)

对我来说重命名文件夹,重启并没有解决问题。但是,在a pages with links posted in a previous comment内,有一个解决我问题的答案。 这个回复说:

If you have references to jars that are not in the ‘libs’ folder, for example if you use ‘classpath variable’, you can resolve the NoClassDefFoundError issue with the new ADT 17 by exporting the references. To export the references: simply go to “Properties > Java Build Path > Order and Export”, and check all the references you want exported.

我必须在src文件夹

之前移动twitter jar