frequent issues arising in android view, Error parsing XML: unbound prefix
XmlAndroidEclipseAndroid LinearlayoutXml Problem Overview
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>
Xml Solutions
Solution 1 - Xml
A couple of reasons that this can happen:
-
You see this error with an incorrect namespace, or a typo in the attribute. Like 'xmlns' is wrong, it should be
xmlns:android
-
First node needs to contain:
xmlns:android="http://schemas.android.com/apk/res/android"
-
If you are integrating AdMob, check custom parameters like
ads:adSize
, you need
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
- If you are using
LinearLayout
you might have to define tools:
xmlns:tools="http://schemas.android.com/tools"
Solution 2 - Xml
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
Turns out I was using custom parameters for AdMob ads like ads:adSize
, but I hadn't added
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
to the layout. Once I added it it worked great.
Solution 3 - Xml
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 android:[name]
. This is what solved my problem.
Solution 4 - Xml
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.
Solution 5 - Xml
This error may occurs in the case you use un-defined prefix such as:
<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 compiler does not know what is XYZ since it was not defined yet.
In your case, you should add below define to root node of the xml file.
xmlns:android="http://schemas.android.com/apk/res/android"
Solution 6 - Xml
>unbound prefix error for ViewPager Indicator:
Along with the following header tags in your 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.
Solution 7 - Xml
For me, I got the "unbound prefix" error on first line here, although I had misspelled android on the fourth line.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
anrdoid:fillViewport="true"
>
Solution 8 - Xml
I had the same problem, and found that the solution was to add the android:tools to the first node. In my case it is a 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">
Solution 9 - Xml
I'll throw in a little more for the newbies and for folks, like myself, that don't understand XML.
The answers above a pretty good, but the general answer is that you need a namespace for any namespace used in the config.xml file.
Translation: Any XML tag name that has
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:intelxdk="http://xdk.intel.com/ns/v1"
Solution 10 - Xml
OK, there are lots of solutions here but non actually explain the root cause of the problem so here we go:
when you see an attribute like android:layout_width="match_parent"
the android
part is the prefix, the format for an attribute here is PREFIX:NAME="VALUE"
. in XML, namespaces and prefixes are ways to avoid naming conflicts for example we can have two distinct attributes with same name but different prefixes like: a:a="val"
and b:a="val"
.
to use prefixes like android
or app
or any other your should define a namespace using xmlns
attribute.
so if you have this issue just find prefixes that do not have a namespace defined, if you have tools:...
you should add tools namespace as some answeres suggested, if you have app:...
attribute you should add xmlns:app="http://schemas.android.com/apk/res-auto"
to the root element
Further reading:
Solution 11 - Xml
This error usually occurs if you have not included the xmlns:mm
properly, it occurs usually in the first line of code.
for me it was..
xmlns:mm="http://millennialmedia.com/android/schema";
that i missed in first line of the code
<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" >
Solution 12 - Xml
You just need to add proper name space in your root tag . xmlns:android="http://schemas.android.com/apk/res/android" Android elemets are declared in this name space.Its same as importing class or package.
Solution 13 - Xml
In my case the error was not caused by any of the above xml namespace issues. Instead it was the location of the android:id
attribute - it needed to be the first item in the particular element's declaration.
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" />
Solution 14 - Xml
Beside all this, There is also a scenario where this error occures-
When you or your library project define custom attribute int attr.xml, And you use these attributes in your layout file without defining namespace .
Generally we use this namespace definition in header of our layout file.
xmlns:android="http://schemas.android.com/apk/res/android"
Then make sure all attributes in your file shoud start with
android:ATTRIBUTE-NAME
You need to identfy if some of your attirbute is not starting with something other than android:ATTRIBUTE-NAME like
temp:ATTRIBUTE-NAME
In this case you have this "temp" also as namespace, generally by including-
xmlns:temp="http://schemas.android.com/apk/res-auto"
Solution 15 - Xml
It usually happens to me when I misspell android - I just type andorid or alike, and it's not obvious at first sight especially after many hours of programming, so I just do a search for "android" one by one and see if search skips one tag - if it does then I have a close look and I see where was typo.
Solution 16 - Xml
I got this error in Xamarin when I was using
<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>
in a layout file without installing the nuget package for android.support.v7.widget.CardView
Installing the applicable nuget package fixed the issue. Hope it helps, I didn't see this answer anywhere in the list