2014-02-23 26 views
0

我對android編程相當陌生,並且遇到了一個奇怪的錯誤,導致我的應用程序無法編譯。xml文件錯誤(android編程):無約束前綴

這裏是我的代碼

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:text="three" /> 
</LinearLayout> 

它給了我 「錯誤:錯誤解析XML:綁定前綴」

回答

1

您需要的命名空間聲明xmlns:android="http://schemas.android.com/apk/res/android"添加到您的LinearLayout

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

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:text="three" /> 
</LinearLayout> 
+0

謝謝你,但我使用這段代碼後仍然有相同的錯誤。 – user3238863

+0

是你的完整xml文件嗎? – Szymon