android视图中出现的常见问题,解析XML时出错:未绑定的前缀

Pen*_*m10 290 xml eclipse android android-linearlayout

我在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>
Run Code Online (Sandbox Code Playgroud)

Pen*_*m10 545

这可能发生的几个原因:

1)您在错误的命名空间或属性中的拼写错误中看到此错误.就像'xmlns'错了,它应该是xmlns:android

2)第一个节点需要包含: xmlns:android="http://schemas.android.com/apk/res/android"

3)如果您要集成AdMob,请检查ads:adSize您需要的自定义参数

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

4)如果您正在使用LinearLayout,则可能需要定义工具:

xmlns:tools="http://schemas.android.com/tools"


Mal*_*ean 101

我要添加一个单独的答案,因为我在这里看不到它.这不是Pentium10所要求的100%,但我最终在这里寻找Error parsing XML: unbound prefix

事实证明我正在使用AdMob广告的自定义参数ads:adSize,但我没有添加

    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
Run Code Online (Sandbox Code Playgroud)

到布局.一旦我添加它,它工作得很好.


Dan*_*iel 63

I had this same problem.

Make sure that the prefix (android:[whatever]) is spelled correctly and written correctly. In the case of the line xmlns:android="http://schemas.android.com/apk/res/android" make sure that you have the full prefix xmlns:android and that it is spelled correctly. Same with any other prefixes - make sure they are spelled correctly and have android:[name]. This is what solved my problem.


Von*_*onC 32

如您所述,您需要指定正确的命名空间.您还会在错误的命名空间中看到此错误.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns="http://schemas.android.com/apk/res/android"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:padding="10dip">
Run Code Online (Sandbox Code Playgroud)

不管用.

更改:

xmlns="http://schemas.android.com/apk/res/android"
Run Code Online (Sandbox Code Playgroud)

xmlns:android="http://schemas.android.com/apk/res/android"
Run Code Online (Sandbox Code Playgroud)

错误消息是指所有以"android:"开头的内容,因为XML不知道" android:"命名空间是什么.

xmlns:android 定义它.


Ngu*_*inh 23

在使用未定义的前缀的情况下可能会发生此错误,例如:

<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>
Run Code Online (Sandbox Code Playgroud)

由于尚未定义,Android编译器不知道XYZ是什么.

在您的情况下,您应该将以下定义添加到xml文件的根节点.

xmlns:android="http://schemas.android.com/apk/res/android"
Run Code Online (Sandbox Code Playgroud)

  • 这个为我做了.这是一个蹩脚的错误:而不是android:layout_weight我输入了anrdoid:layout_weigth. (2认同)

ama*_*Bit 10

ViewPager指标的未绑定前缀错误:

以及parentLayout中的以下标头标记:

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
Run Code Online (Sandbox Code Playgroud)

还添加:

xmlns:app="http://schemas.android.com/apk/res-auto"
Run Code Online (Sandbox Code Playgroud)

这对我有用.


flo*_*cca 9

对我来说,我在第一行得到了"未绑定的前缀"错误,虽然我在第四行有拼错的机器人.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
anrdoid:fillViewport="true"
>
Run Code Online (Sandbox Code Playgroud)


Seb*_*eit 7

我遇到了同样的问题,发现解决方案是将android:tools添加到第一个节点.在我的例子中,它是一个LineraLayout:

    <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">
Run Code Online (Sandbox Code Playgroud)