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

本文讨论了在Android视图开发中遇到的一个常见问题——解析XML时出现'未绑定前缀'错误。不同楼层的网友分享了他们的解决方案,包括检查XML名称空间、属性位置、拼写错误、添加android:tools属性以及为自定义参数添加正确前缀等。这些经验可以帮助开发者解决类似问题。
摘要由CSDN通过智能技术生成

本文翻译自: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. 这帮了我大忙。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值