java.lang.NoClassDefFoundError的Eclipse中,而与蚂蚁 [英] java.lang.NoClassDefFoundError in Eclipse, but not with Ant

查看:211
本文介绍了java.lang.NoClassDefFoundError的Eclipse中,而与蚂蚁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些Android的项目和Eclipse一个比较奇怪的问题。我有一个数字,都用大体相同code,因此搬到了很多code变成一个Android库项目的Andr​​oid项目。这,很长一段时间,相当奏效的三个应用程序。今天,我想使用的第四个应用程序库的欢迎,并遇到了麻烦。基本上,情况如下:

I have a quite weird problem with some Android projects and Eclipse. I have a number of Android projects that all use much of the same code, and have therefore moved a lot of code into an Android Library project. This has, for a long time, worked quite well for three apps. Today, I wanted to use the library for a fourth app as well, and ran into trouble. Basically, the situation is as follows:


  • 库项目:包含一系列的活动,以及一些实用类

  • 新项目:实例化在某种情况下库项目的活动之一

这应该都是微不足道的东西,我甚至做了其他三个应用程序同样的事情与来自相同的库项目完全相同的活动。在新的项目中,我已经引用在项目属性库项目,并从库项目AndroidManifest.xml中添加的活性。现在Eclipse认识到这一点,并让我引用的活动。一切都很好。

This should all be trivial stuff, I have even done the exact same thing in three other applications with the exact same activity from the exact same library project. In the new project I have referenced the library project in the project properties, and added the activity from the library project to AndroidManifest.xml. Eclipse now recognizes this, and lets me reference the activity. Everything is good.

应用程序,直到我执行启动从库项目活动的操作运行正常。在应用程序退出,和logcat的告诉我:

The application runs fine until I execute the action that starts the activity from the library project. The application exits, and logcat tells me this:

FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: no.company.application.base.SomeDetailActivity
    at no.company.someotherapplication.SomeListActivity$4.onClick(SomeListActivity.java:466)
    at android.view.View.performClick(View.java:2538)
    at android.view.View$PerformClick.run(View.java:9152)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3691)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
    at dalvik.system.NativeStart.main(Native Method)

这是乐趣的开始。 我知道,该库项目是捆绑在一起的.apk文件,因为我已经从这个项目运行一些实用的code。但是,编译这个确切的项目从蚂蚁,通过使用命令蚂蚁调试,然后当蚂蚁INSTALLD ,应用程序运行得精细,包括启动活动。因此,完全相同的项目设置运行正常使用Ant,但不使用Eclipse。

This is where the fun starts. I know that the library project is bundled with the .apk, as I have some utility code from this project running. But when compiling this exact project from Ant, by using the commands ant debug and then ant installd, the applications runs just fine, including starting the activity. So, the exact same project setup runs fine with Ant, but not with Eclipse.

我已经试过我已经通过google搜索,如清理所有项目,删除对具体项目的.project和的.classpath和再生他们找到了窍门。我也保证我的清单文件是通过与从工作项目清单文件比较正确的。无论我做什么,我结束了这个问题一次。由于编译和运行只用Ant很好,在我看来,没有什么不对的项目本身,而是我真正需要的是能够编译它通过Eclipse的为好。

I have tried the tricks I have found through googling, such as cleaning all projects, deleting .project and .classpath for the specific projects and regenerating them. I have also ensured that my manifest file is correct by comparing it with the manifest file from the working projects. No matter what I do, I end up with this problem again. As it compiles and runs just fine with Ant, it seems to me that there is nothing wrong with the projects itself, but I really need to be able to compile it through Eclipse as well.

编辑:我只是在反编译由Eclipse中使用dexdump工具创建的APK classes.dex,并能确认类是捆绑在一起的APK。我发现正确的类描述符和实例字段的类。在另一方面,我也反编译使用Ant生成的版本,并得到了不少的差异。太多的赘述。是生成的文件应该使用Ant和Eclipse的时候是一样的吗?

I just decompiled classes.dex in the apk created by Eclipse with the dexdump tool, and was able to confirm that the class is bundled with the apk. I found a class with correct class descriptor and instance fields. On the other hand, I also decompiled the version generated by Ant, and got quite a few differences. Too many to repeat here. Is the generated file supposed to be the same when using Ant and Eclipse?

推荐答案

我只是打这个同样的问题。在我来说,我有它正确设置了Java构建路径,但忘了添加库。进入属性 - > Android的,然后点击添加...,在库部分然后添加库项目。之后,它运行正常。

I just hit this same problem. In my case I had it set properly for the Java build path but forgot to add the library. Go to Properties -> Android then click "Add..." in the Library section then add the library project. After that it ran as expected.

这篇关于java.lang.NoClassDefFoundError的Eclipse中,而与蚂蚁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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