Okay if you’re only just beginning Android development, and you’re developing in Eclipse, you will almost certainly run into the following issue at some point. You’ve done ‘something’ and now your project won’t run and you can’t fix it no matter what you do.
The symptoms
You run your application and a weird new file appears in your project explorer called “main.out.xml”.
The application doesn’t build, and on your “Problems” tab in eclipse you get one or more of the following messages;
Premature end of file. main.out.xml Unparsed aapt error(s)! Check the console for output. Unknown Android Packaging Problem
Your console has the following errors in it;
Error in an XML file: aborting build. main.xml:0: error: Resource entry main is already defined. main.out.xml:0: Originally defined here. main.out.xml:1: error: Error parsing XML: no element found
The cause
You’ll get yourself into this state if you attempt to run your code while you’re editing an xml file which aapt uses to generate any source files.
The solution
If you find this page through googling, chances are you’ve been banging your head against the wall because now your project won’t run at all whatever you do. The mistake you made here was to run while the xml file was open. You should only hit that button when a java source file is open. This won’t help you much now though, as trying to run the project will present you with the following error in a dialog box;
Your project contains error(s). Please fix them before running your application
Remedy is very simple though.
- Delete the “main.out.xml” file that was created
- Select “Clean…” from the “Project” menu
- Open a java source file and run again
and the project will run! From now on, only “Run” from a java source code file. I have also found that this solves the “R can not be resolved” error. As a general rule then, if your plugin is getting confused work through the above steps.
Post Mortem
I don’t know *exactly* how aapt is building your “gen” files when you run, but I do know that it uses the xml files to do it, so my current best working theory as to the cause of this problem is that having the file open in the editor puts some kind of lock on the file that prevents the plugin from parsing it correctly. If anyone has any further insights into this problem I’d love to hear them.
Thank You so much….
you’re very welcome dude.
This problem was driving me nuts. I thought I was the only one going crazy. Thanks.
You’re welcome, drove me nuts too.
Thank you!
No problem!
I love you!! thanks!!
thanks buddy!!
Thank you!!!
Thankl you Man!!!
I love you man, thanks!
Dude, you saved my skull…
i was about to shoot myself, thx. btw what apps do you make?
I actually only dabble in android dev, so no apps to my name yet.
Thank you for this helpful post. I just started working in Android, and my first application was not running last night due to this problem. It is fixed by reading your post. Thanks again and keep it up.
No problem dude, glad it helped.
good solution. i tried one other, but only this one worked.
however can you take a look at this solution?
http://stackoverflow.com/questions/2870689/main-out-xml-error
Thanks a lot. I really appreciate.
Thanks!!! this was GOLD!
I too managed to solve this problem after going through this thread.
Rajavelu
You Saved my life !!!! Gratz!!! and thanx for sharing =P
holy shit it actually worked.
there was also a striing.out.xml i had to delete. this problem has been haunting me for weeks and there has been no solution on the android forum, although thousands of newbies are having this issue from the start with the “hello world” program.
i can’t believe out of all the “dummies” books and online tuturials i read, including those on the android site itself, not one mentioned “don’t try to run the project while the main.xml file is open”. i bet a lot of budding andriod app development carreers were killed by this issue from the start, mine almost was.
and mine mate!
thanks man u r great i really appreciate this help.
thanks Man Really I Superb…..
You’re GREAT!! Thanks a lot!!
This helped me out too. Thanks for posting.
thanks
Sorry! It didn’t work for me.
Any other thoughts?
Thanks
Oops! It did work. Thank you very much
Thanks a lot 🙂
Karab guru, It worked for me.;)
Wow,.. this must be the first IDE on which I got such a problem… can’t run the project while the XML is open???
Thanks man, been stuck for an hour and was gonna stop programming soon!
You know i just made my first app but could not get it to work. Right now i could kiss you. Minus homosexual intent of course.
how about me… i did all the things you sayed but the archive activity_main.out.xml just apear again 😦
Thank you so much it worked…:)