Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android XML Error parsing XML: junk after document element

Tags:

android

xml

I am getting this error:

Multiple annotations found at this line: - The markup in the document following the root element must be well- formed. - error: Error parsing XML: junk after document element

This is appearing on the second TextView in this xml file.

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/text1" 
          android:textSize="16sp" 
          android:textStyle="bold" 
          android:textColor="#FFFF00" 
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent"></TextView>

<TextView android:id="@+id/text2"
    android:textSize="12sp" 
    android:textStyle="bold" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent"
    ></TextView>

<TextView android:id="@+id/text3" 
    android:typeface="sans"
    android:textSize="14sp"
    android:textStyle="italic"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"></TextView>

Any ideas on the mistake I am making? All help is appreciated.

like image 206
Lijap Avatar asked Oct 17 '11 23:10

Lijap


2 Answers

An XML document can only have 1 root element. You have 3 such elements. You should enclose your TextView elements inside a layout, such as a LinearLayout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <!-- TextView elements here -->

</LinearLayout>

Remove the xmlns attribute on the first TextView element.

like image 80
user999717 Avatar answered Oct 12 '22 01:10

user999717


you should encapsule your elements in layouts, such as LinearLayout. You can look at a layout config file in existence.

like image 42
A117 Avatar answered Oct 12 '22 01:10

A117