Mikey Hogarth

Digital Media Development, Code and Opinions

Android Beginner Top Tip – How to fix the ‘main.out.xml’ issue

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.

  1. Delete the “main.out.xml” file that was created
  2. Select “Clean…” from the “Project” menu
  3. 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.

About these ads

37 responses to “Android Beginner Top Tip – How to fix the ‘main.out.xml’ issue

  1. Pradeep November 5, 2010 at 1:53 pm

    Thank You so much….

  2. RedSpade December 14, 2010 at 4:02 am

    This problem was driving me nuts. I thought I was the only one going crazy. Thanks.

  3. agazoth January 8, 2011 at 2:48 pm

    Thank you!

  4. Adriana March 26, 2011 at 11:48 pm

    I love you!! thanks!!

  5. sushant April 14, 2011 at 12:59 pm

    thanks buddy!!

  6. Oskar September 7, 2011 at 7:13 pm

    Thank you!!!

  7. Javier Monterrey September 8, 2011 at 12:02 am

    Thankl you Man!!!

  8. Thilanka September 13, 2011 at 6:12 pm

    I love you man, thanks!

  9. gabriel October 21, 2011 at 4:00 am

    Dude, you saved my skull…

  10. ej November 2, 2011 at 12:36 am

    i was about to shoot myself, thx. btw what apps do you make?

  11. sudhumsoftAltaf Hussain November 2, 2011 at 3:21 am

    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.

  12. Vahhab November 17, 2011 at 8:02 pm

    good solution. i tried one other, but only this one worked.
    however can you take a look at this solution?


  13. Akinola Olayinka February 3, 2012 at 2:52 pm

    Thanks a lot. I really appreciate.

  14. diyoda February 9, 2012 at 2:22 am

    Thanks!!! this was GOLD!

  15. Raja February 19, 2012 at 6:01 am

    I too managed to solve this problem after going through this thread.


  16. Benjamin March 1, 2012 at 4:08 pm

    You Saved my life !!!! Gratz!!! and thanx for sharing =P

  17. michael brown March 24, 2012 at 7:19 pm

    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.

    • michael brown March 24, 2012 at 7:54 pm

      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.

  18. hamza khan April 7, 2012 at 8:03 am

    thanks man u r great i really appreciate this help.

  19. Devendra Singh Rathore April 14, 2012 at 1:14 pm

    thanks Man Really I Superb…..

  20. RaV May 14, 2012 at 6:14 pm

    You’re GREAT!! Thanks a lot!!

  21. RDG July 14, 2012 at 3:49 am

    This helped me out too. Thanks for posting.

  22. Courtney August 3, 2012 at 2:19 am

    Sorry! It didn’t work for me.
    Any other thoughts?


  23. Courtney August 3, 2012 at 2:23 am

    Oops! It did work. Thank you very much

  24. Karthik September 13, 2012 at 12:11 pm

    Karab guru, It worked for me.;)

  25. trance September 20, 2012 at 4:19 am

    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!

  26. Ayas September 25, 2012 at 11:24 am

    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.

  27. Rodolfo October 4, 2012 at 10:33 pm

    how about me… i did all the things you sayed but the archive activity_main.out.xml just apear again :(

  28. preetam November 25, 2012 at 9:20 am

    Thank you so much it worked…:)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 469 other followers

%d bloggers like this: