UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added

佐手、 提交于 2019-12-05 01:58:08

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!