我在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>

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

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”

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

<?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定义了它。

我也有同样的问题。

确保前缀(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"

在我的例子中,错误不是由上述任何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" />

对我来说,我在第一行得到了“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"
>

我遇到了同样的问题,发现解决方案是在第一个节点上添加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">

我要加一个单独的答案,因为我在这里没有看到。这不是Pentium10所要求的100%,但我在这里搜索了“错误解析XML:未绑定前缀”

事实证明,我为AdMob广告使用了自定义参数,如ads:adSize,但我还没有添加

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

对布局。一旦我添加它,它工作得很好。

ViewPager指示器的unbound前缀错误:

在你的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"

这招对我很管用。

如果您没有正确地包含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" >

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

当你或你的库项目定义自定义属性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"

当我拼错android时,通常会发生在我身上——我只是输入andorid或类似的东西,乍一看并不明显,尤其是在编程了好几个小时之后,所以我只是一个接一个地搜索“android”,看看搜索是否跳过了一个标签——如果是,那么我就仔细看看,看看哪里打错了。

对于新手和像我这样不了解XML的人,我将多讲一些内容。

上面的答案非常好,但是一般的答案是您需要为config.xml文件中使用的任何名称空间设置一个名称空间。

翻译:任何XML标记名都是带有名称空间的标记,其中blah是名称空间,fubar是XML标记。名称空间允许您使用许多不同的工具来解释带有自己标记名称的XML。例如,Intel XDK使用的命名空间为intelxdk, android使用的命名空间为android。因此,您需要以下名称空间,否则构建会引发流血(即解析XML错误:未绑定的前缀),这将被翻译为:您使用了一个名称空间,但没有定义它。

  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:intelxdk="http://xdk.intel.com/ns/v1"

您只需要在根标记中添加适当的名称空间。 xmlns: android = " http://schemas.android.com/apk/res/android " Android元素是在这个名称空间中声明的。它与导入类或包相同。

好吧,这里有很多解决方案,但实际上没有解释问题的根本原因,所以我们开始:

当你看到像android:layout_width="match_parent"这样的属性时,android部分是前缀,这里属性的格式是prefix:NAME="VALUE"。在XML中,命名空间和前缀是避免命名冲突的方法,例如,我们可以有两个具有相同名称但不同前缀的不同属性,如:a:a="val"和b:a="val"。

要使用android或app或任何其他前缀,您应该使用XMLNS属性定义一个名称空间。

所以如果你有这个问题,只要找到没有定义名称空间的前缀,如果你有工具:…你应该添加工具命名空间,如果你有app:…属性,您应该将xmlns:app="http://schemas.android.com/apk/res-auto"添加到根元素

进一步阅读:

XML命名空间简单解释

W3中的XML命名空间

我在使用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>

在布局文件中,不安装nuget包

安装适用的nuget包解决了这个问题。希望有帮助,我在列表中没有看到这个答案