views:

2825

answers:

4

Hello,

I have frequent problem in android view, 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>
+4  A: 

I found out that this is because the first node needs to contain: xmlns:android="http://schemas.android.com/apk/res/android"

Pentium10
+2  A: 

As you mention, you need to specify the right namespace. You also see this error with an incorrect namespace.

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

will not work.

Change:

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

to

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

The error message is referring to everything that starts "android:" as the XML does not know what the "android:" namespace is.

xmlns:android defines it.

VonC
A: 

Now, I believe that, almost all the point refered is caused by spelling mistake.

Grape
A: 

I had this same problem make sure that the prefix (android:[whatever]) is spelled correctly and written correctly. In the case of the line xmlns:android="http://schemas.android.com/apk/res/android make sure that you have the full prefix xmlns:android and that it is spelled correctly. Same with any other prefixes - make sure they are spelled correctly and have with android:[name]. This is what solve my problem.

DJ