我在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>
答案 0 :(得分:530)
这可能发生的几个原因:
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"
答案 1 :(得分:100)
我要添加一个单独的答案,因为我在这里看不到它。这不是Pentium10所要求的100%,但我最终搜索Error parsing XML: unbound prefix
原来我使用了ads:adSize
等AdMob广告的自定义参数,但我没有添加
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
到布局。一旦我添加它,它工作得很好。
答案 2 :(得分:61)
我有同样的问题。
确保正确拼写前缀(android:[whatever])并正确写入。如果是xmlns:android="http://schemas.android.com/apk/res/android"
行
确保您拥有完整的前缀xmlns:android
并且拼写正确。与任何其他前缀相同 - 确保它们拼写正确且具有android:[name]
。这就解决了我的问题。
答案 3 :(得分:30)
如您所述,您需要指定right namespace。您还会在错误的命名空间中看到此错误。
<?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">
无效。
变化:
xmlns="http://schemas.android.com/apk/res/android"
到
xmlns:android="http://schemas.android.com/apk/res/android"
错误消息是指所有以“android:”开头的内容,因为XML不知道“
android:
”命名空间是什么。
xmlns:android
定义了它。
答案 4 :(得分: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>
Android编译器不知道什么是XYZ,因为它尚未定义。
在您的情况下,您应该将以下定义添加到xml文件的根节点。
xmlns:android="http://schemas.android.com/apk/res/android"
答案 5 :(得分:10)
ViewPager指标:
的未绑定前缀错误
以及parentLayout中的以下标题标记:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
另外添加:
xmlns:app="http://schemas.android.com/apk/res-auto"
这对我有用。
答案 6 :(得分:9)
对我来说,我在这里的第一行收到了“未绑定的前缀”错误,虽然我在第四行拼错了android。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
anrdoid:fillViewport="true"
>
答案 7 :(得分: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">
答案 8 :(得分:3)
我会为新手以及像我一样不懂XML的人们投入更多。
答案非常好,但一般的答案是你需要config.xml文件中使用的任何命名空间的命名空间。
翻译:任何XML标记名称都是带有命名空间的标记,其中blah是命名空间,fubar是XML标记。命名空间允许您使用许多不同的工具来使用自己的标记名称来解释XML。例如,英特尔XDK使用名称空间intelxdk和android使用android。因此,您需要以下命名空间或构建引发血液(即,解析XML:未绑定前缀的错误),其被转换为:您使用了命名空间,但没有定义它。
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:intelxdk="http://xdk.intel.com/ns/v1"
答案 9 :(得分:2)
如果您未正确包含xmlns:mm
,通常会出现此错误,通常会出现在第一行代码中。
对我而言......
<强>的xmlns:毫米= “http://millennialmedia.com/android/schema”强>
我错过了代码的第一行
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mm="http://millennialmedia.com/android/schema"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="50dp"
android:layout_marginBottom="50dp"
android:background="@android:color/transparent" >
答案 10 :(得分:2)
好的,这里有很多解决方案,但实际上并没有解释问题的根本原因,所以我们开始:
当看到android:layout_width="match_parent"
之类的属性是android
的前缀时,此处的属性格式为PREFIX:NAME="VALUE"
。在XML中,名称空间和前缀是避免命名冲突的方法,例如,我们可以使用名称相同但前缀不同的两个不同属性,例如:a:a="val"
和b:a="val"
。
要使用诸如android
或app
之类的前缀,您应该使用xmlns
属性定义名称空间。
因此,如果您遇到此问题,只需查找没有定义名称空间的前缀,如果您使用tools:...
,则应添加工具名称空间,如建议的一些答案;如果您具有app:...
属性,则应添加xmlns:app="http://schemas.android.com/apk/res-auto"
到根元素
进一步阅读:
答案 11 :(得分:1)
在我的情况下,错误不是由上述任何xml命名空间问题引起的。相反,它是android:id
属性的位置 - 它需要是特定元素声明中的第一个项目。
所以这个:
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/bottomtext"
android:singleLine="true" />
......需要这样读:
<TextView android:id="@+id/bottomtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
答案 12 :(得分:1)
除此之外,还有一个出现此错误的情况 -
当您或您的库项目定义自定义属性int attr.xml时,您在布局文件中使用这些属性而不定义命名空间。
通常我们在布局文件的标题中使用此命名空间定义。
xmlns:android="http://schemas.android.com/apk/res/android"
然后确保文件中的所有属性都以
开头android:ATTRIBUTE-NAME
你需要确认你的某些attirbute是不是以android以外的其他东西开头:ATTRIBUTE-NAME如
temp:ATTRIBUTE-NAME
在这种情况下,你有这个&#34; temp&#34;也作为命名空间,通常包括 -
xmlns:temp="http://schemas.android.com/apk/res-auto"
答案 13 :(得分:1)
您只需在根标记中添加适当的名称空间即可。 的xmlns:机器人=&#34; HTTP://schemas.android.com/apk/res/android" Android元素在此名称空间中声明。与导入类或包相同。
答案 14 :(得分:0)
当我拼错android时,通常会发生这种情况 - 我只是输入ororid或者类似的东西,特别是经过几个小时的编程后,一开始并不明显,所以我只是逐个搜索“android”,看看是否搜索跳过一个标签 - 如果是,那么我仔细看看,我看到哪里是拼写错误。
答案 15 :(得分:0)
我在使用Xamarin时遇到此错误
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardElevation="4dp"
card_view:cardCornerRadius="5dp"
card_view:cardUseCompatPadding="true">
</android.support.v7.widget.CardView>
在布局文件中,而未安装android.support.v7.widget.CardView的nuget包
安装适用的nuget软件包可解决此问题。希望有帮助,我在列表中的任何地方都没有看到这个答案