Android: Error parsing XML: unbound prefix - android

I would like to implement the color picker library at https://github.com/attenzione/android-ColorPickerPreference:
To setup, in a dialog, the xml is added according to the instruction in website, and is as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<RelativeLayout
android:id="#+id/message_dialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/layout_round_corners_blue" >
<net.margaritov.preference.colorpicker.ColorPickerPreference // error line
android:layout_width="wrap_content"
android:layout_height="wrap_content"
holo:defaultValue="#color/pumpkin_orange"
holo:key="color1"
holo:summary="#string/color1_summary"
holo:title="#string/color1_title" />
</RelativeLayout>
</RelativeLayout>
Question:
The xml reports error error: Error parsing XML: unbound prefix at the above error line marked.
What is the problem for the above xml?

you have to change this <net.margaritov.preference.colorpicker.ColorPickerPreference to your package where you add this class like
<com.example.yourPackagewhereyouAddThisClass.ColorPickerPreference
like
net.margaritov.preference.colorpicker
change this above to your package Name where you add you ColorPickerPreference Class

Related

Why is there a parse error in my android layout XML?

My activity_main.xml layout file indicates an error: error parsing XML: unbound prefix. No idea why - it seems related to the AdView.
<?xml version="1.0" encoding="utf-8"?>
<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="horizontal">
<-- ERROR HERE - error parsing XML: unbound prefix -->
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-xxxxxx/xxxxxx"
ads:adSize="SMART_BANNER"/>
</LinearLayout>
You forgot to define the ads prefix for the custom attributes (adSize & adUnitId).
Add to the LinearLayout container:
xmlns:ads="http://schemas.android.com/apk/res-auto"
More details here.
You may have forgotten to add this
xmlns:ads="http://schemas.android.com/apk/res-auto"
Have you also included the right library?

Android following class could not be found

I'am trying to load a spinner to my layout and keep geting this error:
The following classes could not be found:
- Spinner (Change to android.widget.Spinner, Fix Build Path, Edit XML)
heres my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Spinner
android:id="#+id/spn_dates"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="displayDatesToSpiner" />
<ListView
android:id="#+id/LST_bought_products"
android:layout_width="match_parent"
android:layout_height="302dp" >
</ListView>
</LinearLayout>
Thanks
This sometimes happens when you rename the standard AppTheme in your android manifest. It will build and deploy just fine, but the xml design editor won't render it.
This is usually because there's an invalid attribute somewhere.
Remove the onClick and it will work.

Custom elements and package name

When creating a custom element with attributes in Android I need to put the namespace of the application in the layout.
For example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:whatever="http://schemas.android.com/apk/res/org.example.mypackage"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.example.mypackage.MyCustomView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
whatever:my_custom_attribute="Hello, world!" />
</LinearLayout>
Does this also requires that the structure of my project in Eclipse be the same as the name of the Android package as definied in the Manifest - as per the example?
Would this work too:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:whatever="http://schemas.android.com/apk/res/org.mycompany.myproduct"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.example.mypackage.MyCustomView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
whatever:my_custom_attribute="Hello, world!" />
</LinearLayout>
Its the package name of your application that should be reflected. So its correct to use it as you are doing.
For example:
In xmlns:whatever="http://schemas.android.com/apk/res/org.mycompany.myproduct the last part org.mycompany.myproduct should be the same as your package name. And you may change xmlns:whatever to anything like xmlns:theblitz but then make sure you do use theblitz as a prefix for your attributes in the xml.
For more info, read this

Android Application:Error "Found text"

I have been following a book on Android "Beginning Android Application". I have been trying to figure out an application which shows images in a view. But unfortunately I could not run the application because of the following errors:
[2012-04-24 19:37:33 - Gallery] F:\eclipse workspace\Gallery\res\values
\attrs.xml:2:error: Found text "
[2012-04-24 19:37:33 - Gallery] ​​​​ " where item tag is expected
For convenience I am giving here the codes.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Bilai"
/>
<Gallery
android:id="#+id/gallery1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#+id/image1"
android:layout_width="320px"
android:layout_height="250px"
android:scaleType="fitXY"
/>
</LinearLayout>
This application requires another xml file. It is named as attrs.xml under res/values.
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
​<declare-styleable name="Gallery1" >
​​​​<attr name="android:galleryItemBackground" />
​​​</declare-styleable>
</resources>
I think the problem lies within attrs.xml, but I dont know whats going on. And because of this the R.styleable also doesnt work either. Please help. Thanks in advance
I think you have some characters before each line in your attrs.xml due to a copy/past method.
Can you try to reformat your code by placing your text cursor at the beginning of each line and delete to return to previous line ?

error: Error parsing XML: unbound prefix

I understand this can be caused by spelling and grammatical errors and I have double checked this part of the code. My main is to have the image 'alien' in a specific position on the canvas. The error comes from this code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/spaceinvaders"
>
<ImageView
android:id="#+id/alien"
android:src="#drawable/alien"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
andriod:layout_marginTop="120dip"/>
</LinearLayout>
I believe it is caused by your last line.
andriod:layout_marginTop="120dip"/>

Categories

Resources