意外的顶级异常:java.lang.IllegalArgumentException:已添加
我是 Android 新手,正在尝试启动该项目,该项目正在构建和部署良好。但每次我尝试从 eclipse 启动应用程序时,我都会收到此错误:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/.../model/AvailabilityRequest$DAY_TIME_PREFERENCE;
[2012-02-06 17:32:11 - main-app] Dx at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[2012-02-06 17:32:11 - main-app] Dx at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[2012-02-06 17:32:11 - main-app] Dx at com.android.dx.command.dexer.Main.processClass(Main.java:486)
...
[2012-02-06 17:32:11 - main-app] Dx at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
[2012-02-06 17:32:11 - main-app] Dx 1 error; aborting
[2012-02-06 17:32:11 - main-app] Conversion to Dalvik format failed with error 1
我已经为这个愚蠢的事情浪费了大量时间。显然,这是已知问题,但对我来说没有任何作用。
我拥有的:
操作系统 - OS X,我认为这很重要;
IDE - Eclipse 3.7.1
ADT - 版本:15.0.1.v201111031820-219398
构建工具 - Maven
到目前为止我尝试过的:
- Properties->Java Build Path->Libraries 删除除 Android xyz 之外的所有库,然后 Maven->Update Project Configuration,同时清理项目;
- 关闭和重新打开 Eclipse 的魔法;
- 删除并重新创建项目及其库(根据错误消息的文本,存在一些重复的源,位于主项目中使用的 2 个库之一中)。
在上述变体之一(通常是第一个)之后,它开始工作,但我可以花 20 分钟或几个小时才能使它工作......,今天我根本无法做到这一点。
任何想法将不胜感激。
I'm new to Android, trying to launch the project, which is being built and deployed well. But every time I make a try to start the app from eclipse, I get this error:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/.../model/AvailabilityRequest$DAY_TIME_PREFERENCE;
[2012-02-06 17:32:11 - main-app] Dx at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[2012-02-06 17:32:11 - main-app] Dx at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[2012-02-06 17:32:11 - main-app] Dx at com.android.dx.command.dexer.Main.processClass(Main.java:486)
...
[2012-02-06 17:32:11 - main-app] Dx at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
[2012-02-06 17:32:11 - main-app] Dx 1 error; aborting
[2012-02-06 17:32:11 - main-app] Conversion to Dalvik format failed with error 1
I've killed enormous amount of time for this stupid thing. Obviously, this is known problem, but nothing works for me.
What I have:
Operation system - OS X, which is important I think;
IDE - eclipse 3.7.1
ADT - Version: 15.0.1.v201111031820-219398
Build tool - Maven
What I've tried so far:
- Properties->Java Build Path->Libraries to remove all the libraries except Android x.y.z, then Maven->Update Project Configuration, also to clean the project;
- Magic with closing and reopening eclipse;
- Dances with deleting and recreating the project and the libraries for it (according to the text of error message, there is some duplication of the sources, which are in one of the 2 libraries, used in the main project).
After one of the variants above (usually the 1st one) it starts to work, but I can spend 20 mins to make it work or several hours..., today I can't manage to do it at all.
Any idea would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的 Eclipse 类路径包含多个同名/包的类,ADT 将抛出这样的异常。在本例中,它在 Maven 依赖项中遇到了多个
AvailabilityRequest
类实例。您可以通过查找哪些类路径依赖项包含相同的类文件来解决此问题(按 Ctrl-Alt-T 并输入 AvailabilityRequest 即可执行此操作)。
然后,您可以在 m2e POM 编辑器中打开 POM 并转到“依赖关系层次结构”选项卡。这将允许您选择无关的依赖项,然后您可以通过右键单击并选择“排除 Maven Artifact...”来排除该依赖项,这将自动向您的 POM 添加
元素。这将从 Eclipse 类路径中删除重复的 JAR,并允许您构建项目。另外,您应该小心添加到 POM 中的依赖项。
The ADT will throw an exception like this if your Eclipse classpath contains more than one class of the same name/package. In this case it is encountering more than one instance of the
AvailabilityRequest
class in your Maven dependencies.You can resolve this by finding which classpath dependencies contain the same class files in them (hitting Ctrl-Alt-T and typing in AvailabilityRequest will do this).
You can then open your POM in the m2e POM editor and go to the Dependency Hierarchy tab. This will allow you to select the extraneous dependency, which you can then exclude by right-clicking and selecting "Exclude Maven Artifact..." which will automatically add an
<exclusions>
element to your POM. This will remove the duplicate JAR from your Eclipse classpath and allow you to build you project.Also, you should be careful about what dependencies you add to your POM.
嗯,据我了解,这里最主要的是我使用 maven 作为构建工具。我可以毫无问题地构建和部署项目,但无法从环境(eclipse)启动它。
如果我没记错的话,当您进入 eclipse 的“运行”->“运行配置”并创建一个“Android 应用程序”来启动您的项目时,您基本上会询问 eclipse (Android SDK)使用 Ant 为您构建 .apk,而不是使用 maven。 Eclipse 使用 Ant 构建项目并将生成的 .apk 推送到设备/模拟器。但由于项目的所有设置都在 .pom 文件中,Ant 无法构建项目并给出此类错误。
解决方案:
部署应用程序后,直接从设备/模拟器启动您的应用程序,而不是通过运行菜单。
如果您想调试您的应用程序,请使用 DDMS 的调试,而不是 eclipse 提供的调试。
如果您不知道 DDMS 在哪里(就像我一样) - 在 Mac 中,窗口 -> 打开透视图 -> 其他... 选择 DDMS从菜单;您可以将它作为书签与 eclipse 的 Debug 和 Java 一起放置。在 DDMS 中,您会发现所有很酷的工具,包括调试。
PS这是来自初学者和初学者的回答...如果您发现我有错,请告诉我或随时编辑我的答案。
Well, as far as I understand, the main thing here was that I was using maven as a building tool. I could build and deploy project without any problem, but I couldn't start it from the environment (eclipse).
If I'm not wrong, when you go to eclipse's Run->Run Configurations and create an Android Application to launch your project, you basically ask eclipse (Android SDK) to build the .apk with Ant for you, not with maven. Eclipse builds the project with Ant and pushes the generated .apk to the device/simulator. But since all the settings of the project are in .pom files, Ant can't build the project and gives the errors of this kind.
Solution:
Start your app right from the device/simulator after you deployed it, not through Run menu.
If you want to debug your app, use DDMS' debug, not the one eclipse provides.
In case you don't know where DDMS is (like me in my case) - in Mac it's Window->Open Perspective->Other... choose DDMS from menu; you can put it as a bookmark together with eclipse's Debug and Java. In DDMS you'll find all the cool tools, including debug.
P.S. This is a response from a beginner and for beginners... If you see something where I'm wrong, please, let me know or feel free to edit my answer.