我在android视图中经常出现问题,错误解析XML:第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>

当前回答

对我来说,我在第一行得到了“unbound prefix”错误,尽管我在第四行拼错了android。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
anrdoid:fillViewport="true"
>

其他回答

对我来说,我在第一行得到了“unbound prefix”错误,尽管我在第四行拼错了android。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
anrdoid:fillViewport="true"
>

除了所有这些,还有一个场景,这个错误发生-

当你或你的库项目定义自定义属性int attrx .xml,你使用这些属性在你的布局文件没有定义命名空间。

通常我们在布局文件的头文件中使用这个命名空间定义。

xmlns:android="http://schemas.android.com/apk/res/android"

然后确保文件中的所有属性都以

android:ATTRIBUTE-NAME

你需要识别你的一些属性是否以android:ATTRIBUTE-NAME以外的东西开始

temp:ATTRIBUTE-NAME

在本例中,您还将这个“temp”作为名称空间,通常包括-

xmlns:temp="http://schemas.android.com/apk/res-auto"

正如您提到的,您需要指定正确的名称空间。您还会看到带有不正确名称空间的此错误。

<?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"

to

xmlns:android="http://schemas.android.com/apk/res/android"

错误消息引用以“android:”开头的所有内容,因为XML不知道“android:”命名空间是什么。 android定义了它。

出现这种情况的几个原因:

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)如果你使用线性布局,你可能需要定义工具:

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

如果您没有正确地包含xmlns:mm,则通常会出现此错误,它通常出现在代码的第一行。

对我来说…

xmlns:mm=“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" >