error: Error parsing XML: mismatched tag

26,287

Solution 1

The closing tags for the <ImageView> and <Button> tags are missing.

You can add a / at the end of the tags to make them self-closing:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >


    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/android" />

    <Button
        android:id="@+id/btnChangeImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Change Image" />

</LinearLayout>

Solution 2

Agree with the above answers, but I think the answers can be added to by showing you a simple way to debug this yourself for the future (teach a man to fish...).

Modern browsers have XML parsers built in. Open your original file using Internet Explorer. It gives this error message:

End tag 'LinearLayout' does not match the start tag 'Button'. 

Once you close the Button node, save the file and open it again. It gives you this error:

End tag 'LinearLayout' does not match the start tag 'ImageView'.

Close that tag, save and re-open file. The well formed XML renders in the browser. While normally I an not a big proponent of IE, it gives a better error message than Chrome, and it allows you to collapse and expand each level of nested XML, which is really helpful for more complex XML. I hope this technique helps you out in the future.

Solution 3

Need to close the Button and ImageView Tags.

For every Tag / Node / Element you open, you need to also close them.

For example: if you open with <Tag> you need to close with </Tag> or add a slash at the end of the tag like this: <Tag />

Solution to your problem is bellow:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >


    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/android" /> <!-- This one here -->

    <Button
        android:id="@+id/btnChangeImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Change Image" /> <!-- This one here -->

</LinearLayout>

OR

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >


    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/android" >
    </ImageView> <!-- This one here -->

    <Button
        android:id="@+id/btnChangeImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Change Image" >
    </Button> <!-- This one here -->

</LinearLayout>
Share:
26,287
Harrison
Author by

Harrison

Updated on July 09, 2022

Comments

  • Harrison
    Harrison almost 2 years

    I am getting this error:

    Error parsing XML: mismatched tag.

    If anyone knows how to fix this, can you please let me know what I'm missing, thank you.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
    
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/android" >
    
        <Button
            android:id="@+id/btnChangeImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Change Image" >
    
    </LinearLayout>
    
  • Buzzy Hopewell
    Buzzy Hopewell almost 5 years
    Thank you, this advice really helped me to debug missing end tags in my document with 43K lines.