本文翻译自:frequent issues arising in android view, Error parsing XML: unbound prefix
I have frequent problem in android view, Error parsing XML: unbound prefix on Line 2
. 我在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>
#1楼
参考:https://stackoom.com/question/9jQ9/android视图中经常出现的问题-解析XML时出错-未绑定前缀
#2楼
In my case the error was not caused by any of the above xml namespace issues. 就我而言,该错误不是由上述任何xml名称空间问题引起的。 Instead it was the location of the android:id
attribute - it needed to be the first item in the particular element's declaration. 相反,它是android:id
属性的位置-它必须是特定元素的声明中的第一项。
So this: 所以这:
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/bottomtext"
android:singleLine="true" />
... needed to read like this: ...需要这样阅读:
<TextView android:id="@+id/bottomtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
#3楼
For me, I got the "unbound prefix" error on first line here, although I had misspelled android on the fourth line. 对我来说,尽管我在第四行拼错了android,但在第一行出现了“ unbound prefix”错误。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
anrdoid:fillViewport="true"
>
#4楼
I had the same problem, and found that the solution was to add the android:tools to the first node. 我有同样的问题,发现解决方案是将android:tools添加到第一个节点。 In my case it is a LineraLayout: 就我而言,这是一个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">
#5楼
I'm going to add a separate answer just because I don't see it here. 我将添加一个单独的答案,只是因为我在这里看不到它。 It's not 100% what Pentium10 asked for, but I ended up here by searching for Error parsing XML: unbound prefix
这不是Pentium10要求的100%,但是我在这里最终通过搜索Error parsing XML: unbound prefix
Turns out I was using custom parameters for AdMob ads like ads:adSize
, but I hadn't added 原来我为AdMob广告使用了自定义参数,例如ads:adSize
,但是我没有添加
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
to the layout. 到布局。 Once I added it it worked great. 一旦添加,它就很棒。
#6楼
unbound prefix error for ViewPager Indicator: ViewPager指示器的未绑定前缀错误:
Along with the following header tags in your parentLayout: 以及您的parentLayout中的以下标头标记:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
Also add: 还添加:
xmlns:app="http://schemas.android.com/apk/res-auto"
This did the trick for me. 这帮了我大忙。