有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java 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.安卓.ex.twitter4j.TwitterApp.askOAuth(TwitterApp.java:110)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at com.pigmal.安卓.ex.twitter4j.TwitterApp.onClick(TwitterApp.java:144)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at 安卓.view.View.performClick(View.java:2482)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at 安卓.view.View$PerformClick.run(View.java:9077)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at 安卓.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 安卓.os.Looper.loop(Looper.java:130)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at 安卓.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.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-30 11:26:16.878: E/AndroidRuntime(11098):    at com.安卓.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专家


共 (5) 个答案

  1. # 1 楼答案

    试试这个,这对我很管用

    1. 转到构建路径,删除twitter4j库,然后确定

    2. 转到构建路径,选择添加外部库,然后转到从github下载的项目文件夹,然后转到它的lib文件夹,你会在那里找到twitter4j文件,只选择twitter4j核心(但只有当仍然失败时,才包括twitter4j流,直到那时只保留核心),然后执行Ok

  2. # 2 楼答案

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

  3. # 3 楼答案

    我想你最好也为这个问题贴上安卓标签。我在之前的帖子上看到过一些人有类似的问题,甚至是因为ADT版本。理想情况下,由于您已经将代码放在libs文件夹中,所以应该能够获得所有这些类。但这似乎是一些运行时问题,而不是编译时问题

    这似乎也是android特有的


    您是否在类路径中手动添加了jar? 通常,当一个jar被添加到libs文件夹中时,它开始出现在Android Dependencies中,而不是直接出现在快照中

  4. # 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,而不仅仅是在之后清理项目

  5. # 5 楼答案

    对我来说,重命名文件夹,重新启动并不能解决问题。但是,在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