aChipmunk aChipmunk - 1 year ago 48
Android Question

Unexpected namespace prefix "xmlns" found for tag ListView

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!

Answer Source

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