Error parsing XML: no element found

31,726

Solution 1

delete the main.out.xml in project view and re-run as android application

Solution 2

I had a similar problem once.

Rebuilding/cleaning the project and restarting Eclipse helped for me.

Solution 3

Try to end your Main or Sub Layout like:

</LinearLayout>

Solution 4

Error message I got:

Error:(43) Error parsing XML: no element found

and

Error:Execution failed for task ':app:processDebugResources'.

com.android.ide.common.process.ProcessException: Failed to execute aapt

Solution: In my case, project activity_main.xml is initiated with the code

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.batvibes.battybirthday.Main1Activity">

and I forgot the below end tag.

</android.support.constraint.ConstraintLayout>

Disclaimer: I am totally new to android development. My suggestion, please check all tags opening and closing and go to next step of debugging.

Share:
31,726
DuxClarus
Author by

DuxClarus

Worked for a local media production house for 7 years. In that time I used Unity and C# exclusively. I've programmed educational video games, brochure applications, interactive displays apps, educational apps, AR apps, and VR apps. Majority of the products where Android/iOS based with a few here and there that were Windows products. I'm now on the job hunt due to being let go(financial reasons within the company). In the meantime I'm expanding my skill-set.

Updated on July 15, 2022

Comments

  • DuxClarus
    DuxClarus almost 2 years

    First off forgive me if I posted this question wrong. I've used stackoverflow for many problems but this is the first time I couldnt already find an answer to my problem. So, if I'm doing something wrong please let me know and I'll repost / edit the question.

    Now unto business. I've just recently started development w/ the Android SDK and I'm following the basic tutorial from http://developer.android.com/resources/tutorials/hello-world.html#avd I've gotten up the xml editting part and when I make all the changes to the xml files main.xml and strings.xml this error occurs. Also, when I compile the project, the compilation process generates a main.out.xml file that is empty. I don't know what it is or its purpose.

    The error:

    [2011-12-30 16:10:02 - Hello Razor] res\layout\main.xml:0: error: Resource entry main is already defined. [2011-12-30 16:10:02 - Hello Razor] res\layout\main.out.xml:0: Originally defined here. [2011-12-30 16:10:02 - Hello Razor] C:\Users\Dux69\workspace\Hello Razor\res\layout\main.out.xml:1: error: Error parsing XML: no element found [2011-12-30 16:10:13 - Hello Razor] Error in an XML file: aborting build.

    My project is setup for platform: Android 2.3.3 API Level: 10

    I don't know if it makes a difference or not but I'm using my Android Incredible for running/debugging the application not a Android Virtual Device. If there is any more information needed let me know and I'll post it ASAP.

    Here are the three code files I'm using:

    main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <TextView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/textview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:text="@string/hello_O" />
    

    strings.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <string name="hello_O">Baba in the house, Razor Activity!</string>
    <string name="app_name">Hello Razor App</string>
    </resources>
    

    razorActivity.java

    package hello.Razor;
    
    import android.R;
    import android.app.Activity;
    import android.os.Bundle;
    
        public class razorActivity extends Activity
        {
            /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState)
            {
               super.onCreate(savedInstanceState);
               setContentView(R.layout.main);
            }
        }
    
  • Riccardo Bocci
    Riccardo Bocci over 12 years
    if doesn't works, delete main.out.xml and do a Clean, then open your razorActivity.java and re-run. It's a common aapt error
  • DuxClarus
    DuxClarus over 12 years
    wow thanks for the help. I have to go through a whole process of shutting down eclipse, re-opening it, deleting that file, and then cleaning. What a hassle man. Is there anyway that I can fix this?
  • Riccardo Bocci
    Riccardo Bocci over 12 years
    when you the first time tried to "Run" your application you were executing the XML file (strange behaviour from eclipse i understand you), so when you run the app it launches again and again the XML file due the fact it's the first in your history run.. Just delete, open your razorActivity.java and launch from Run -> Run History and it should be finally fixed forever
  • DuxClarus
    DuxClarus over 12 years
    Thanks for the feedback, Riccardo Bocci and others. Now that I understand this nuisance maybe now I can start some actual android programming!
  • Pratik Patel
    Pratik Patel over 5 years
    I was facing this in xamarin studio by cleaning and rebuilding it did resolve.!