我在Android视图中经常遇到这个错误:Error parsing XML: unbound prefix on Line 2.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:id="@+id/myScrollLayout" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Family" android:id="@+id/Family"
android:textSize="16px" android:padding="5px"
android:textStyle="bold" android:gravity="center_horizontal">
</TextView>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:scrollbars="vertical">
<LinearLayout android:orientation="vertical" android:id="@+id/myMainLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content">
</LinearLayout>
</ScrollView>
</LinearLayout>
我发现这是因为在第一行代码需要包含
xmlns:android="http://schemas.android.com/apk/res/android"
我也遇到了这个问题,然后发现是前缀(android:[whatever])拼写错误。在
xmlns:android="http://schemas.android.com/apk/res/android
这一行确保你有完整的前缀xmlns:android
,而且它被正确的拼写。和其他的前缀一样-确保他们拼写正确,而且有android:[name]
.。我是这样解决我的问题的。
这个错误可能发生在你没有定义前缀的情况下,像这样:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabHost
XYZ:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</TabHost>
因为它还没有被定义,所以android编译器不知道什么是XYZ。
在你的情况下,你需要将下边的定义添加到xml文件的根节点中。
xmlns:android="http://schemas.android.com/apk/res/android"