Unexpected namespace prefix “xmlns” found for tag ListView

折月煮酒 提交于 2019-12-11 20:27:05

问题


I added a list view under RelativeLayout in activity_main.xml to create a simple list view for the main activity (please excuse me if I am using wrong terminology. I am very new to android dev).

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <ListView 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/listview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

This worked perfectly for some time.
I am note sure what I did because now I am getting a red error circle on the line android:id="@+id/listview" The error i am getting is: Unexpected namespace prefix "xmlns" found for tag ListView

Eclipse wont let me compile the project even though it was just working.

Thanks in advance!


回答1:


You can remove the xmlns:android="http://schemas.android.com/apk/res/android" from your listview definition, it is only necessary once for the xml file.

    <ListView 
    android:id="@+id/listview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

xmlns is the namespace you are defining, in this case you are saying at the beginning of the file that "android" is linked to the namespace at

http://schemas.android.com/apk/res/android

so there is an error when you are attempting to redefine it




回答2:


To avoid this type of situation in future, I believe it's sufficient to inform the application only once about xml namespace at outermost Layout or View of xml file.

It's very odd because parser should reject any duplicate namespace declaration.

So you have to remove xmlns:android="http://schemas.android.com/apk/res/android from all the spaces (here ListView) except outermost Layout/View (here RelativeLayout)

OR

You can do a temporary solution by cleaning that project. Though it's a temporary solution, the plus point is that you don't have to do any code changes.



来源:https://stackoverflow.com/questions/16952259/unexpected-namespace-prefix-xmlns-found-for-tag-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!