2015-04-30 48 views
2

我收到此錯誤:錯誤:錯誤解析XML:不匹配的標籤

Error parsing XML: mismatched tag.

如果有人知道如何解決這個問題,你可以請讓我知道我錯過了什麼,謝謝。

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

回答

3

<ImageView><Button>標籤中的結束標記丟失。

您可以在標籤的末尾添加/,使他們自閉:

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

需要關閉ButtonImageView標籤。

對於您打開的每個標籤/節點/元素,您還需要關閉它們。

例如:如果你<Tag>打開你需要這樣的標籤月底關閉與</Tag>或添加斜線:<Tag />

解決你的問題是波紋管:

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

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

同意上面的答案,但我認爲可以通過向您顯示一個簡單的方法來調試此答案來添加答案你自己的未來(教一個人釣魚......)。

現代瀏覽器內置了XML解析器。使用Internet Explorer打開原始文件。它給出此錯誤消息:

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

一旦關閉了按鈕節點,保存該文件並再次打開它。它給你這個錯誤:

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

關閉該標記,保存並重新打開文件。格式良好的XML在瀏覽器中呈現。雖然通常我並不是IE的主要支持者,但它提供了比Chrome更好的錯誤消息,並且它允許您摺疊和展開嵌套XML的每個級別,這對於更復雜的XML非常有用。我希望這種技術能夠在未來幫助你。