2012-06-17 88 views
1

我是java編程新手,現在嚴格遵循一個教程。直到發生了一些我無法修復的事情時,我已經深入瞭解它。我搜索谷歌,一遍又一遍地查看代碼,並沒有看到任何錯誤。這裏是我的代碼截圖.... nvm我不允許發佈圖片,因爲我是新手,所以這裏是代碼複製。第一個X表示錯誤解析XML:沒有正確形成(無效標記),第二個X表示XML文檔結構必須在同一實體內開始和結束。我感謝所有的幫助,謝謝。解析XML時出錯:格式不正確(無效標記)

< ?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" 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/myMessage" 
     android:text="@string/hello" /> 

    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/myButton" 
     android:text="@string/answer" 
     /> 

< LinearLayout--------1st X is located here. The < is not spaced in the code but spaced here because that was the only way i could put it here 
    android:layout_width="fill_parent" 
    android:layout_height="20dp" 
    android:orientation="horizontal"> 


    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:background="#ff0000" 
     android:textColor="#000000" 
     android:text="red" /> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:background="#00ff00" 
     android:textColor="#000000" 
     android:text="green" /> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:background="#0000ff" 
     android:textColor="#000000" 
     android:text="blue" /> 

<LinearLayout>---------2nd X is located here. The < is not spaced in the code but spaced here because that was the only way i could put it here and there is a/in between < and LinearLayout 
+0

完成XML代碼。其不完整 – Akilan

回答

1

xml結構不好......下面是更正後的一個。 不應該有< 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" 
android:orientation="vertical"> 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/myMessage" 
    android:text="@string/hello" /> 

<Button 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/myButton" 
    android:text="@string/answer" 
    /> 

<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="20dp" 
android:orientation="horizontal"> 


<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:gravity="center" 
    android:background="#ff0000" 
    android:textColor="#000000" 
    android:text="red" /> 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:gravity="center" 
    android:background="#00ff00" 
    android:textColor="#000000" 
    android:text="green" /> 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:gravity="center" 
    android:background="#0000ff" 
    android:textColor="#000000" 
    android:text="blue" /> 

</LinearLayout > 
</LinearLayout > 
0

你錯過在底部有一個結束標記</LinearLayout>。在這裏工作的一個`

<TextView 
    android:id="@+id/myMessage" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" /> 

<Button 
    android:id="@+id/myButton" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/answer" /> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="20dp" 
    android:orientation="horizontal" > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:background="#ff0000" 
     android:gravity="center" 
     android:text="red" 
     android:textColor="#000000" /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:background="#00ff00" 
     android:gravity="center" 
     android:text="green" 
     android:textColor="#000000" /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:background="#0000ff" 
     android:gravity="center" 
     android:text="blue" 
     android:textColor="#000000" /> 
</LinearLayout> 

`

0

你不能讓給予公開的標籤和標籤名之間的空間。給線性佈局標籤沒有空間像

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" > 

這是錯誤的

< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"> 
0

<LinearLayout標籤中的空格。使用<LinearLayout,而不是作爲< LinearLayou

<?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" 
    android:orientation="vertical" > 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="20dp" 
    android:orientation="horizontal"> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/myMessage" 
     android:text="@string/hello" /> 

    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/myButton" 
     android:text="@string/answer" 
     /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:background="#ff0000" 
     android:textColor="#000000" 
     android:text="red" /> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:background="#00ff00" 
     android:textColor="#000000" 
     android:text="green" /> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:background="#0000ff" 
     android:textColor="#000000" 
     android:text="blue" /> 
</LinearLayout> 
</LinearLayout> 
相關問題