2011-10-17 27 views
9

我收到此錯誤後垃圾 - 根元素下列文件中的標記必須 形成良好。 - 錯誤:在文檔元素之後解析XML:垃圾時出錯Android的XML錯誤解析XML:</p> <p>在這條線找到多個註釋:文檔元素

這出現在此xml文件的第二個TextView中。

<?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> 

對我犯的錯誤有任何想法嗎? 所有幫助表示讚賞。

回答

25

XML文檔只能有1個根元素。你有3個這樣的元素。你應該附上您的TextView元素的佈局裏面,比如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> 

刪除的xmlns第一TextView元素上的屬性。

+2

謝謝你,我會接受你的回答! – Lijap

0

你應該在佈局中包裝你的元素,比如LinearLayout。您可以查看存在的佈局配置文件。