开发者

What does unbound prefix mean, when parsing XML?

I Have made a xml file in my android app for the Custom Widget and the error is:

Error parsing XML: unbound prefix

Here is my xml file:

<?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">
    <com.example.CustomWidget.MyView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        androi开发者_运维知识库d:layout_height="fill_parent"

        android:id="@+id/surface"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_weight="1"/>

</LinearLayout>

com.example.CustomWidget is the name of my package and MyView is the name of my class file where I made the custom Widget.


The second XML namespace is correct however it is the namespace of your custom widget so you need to define the name space appropriately:

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

becomes:

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

Thereafter any custom attribute elements you define for your custom view will be referred to as:

mynamespace:my_defined_attribute="success"

instead of :

android:layout_width="fill_parent"


In your XML file, you have to add a line:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.myproject.winedeals"
 .....
 .....>


Take the second XML Namespace declaration out:

 <?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">
   <com.example.CustomWidget.MyView
     android:id="@+id/surface
     android:layout_width="fill_parent"
     android:layout_height="fill_parent" 
     android:layout_weight="1"
     android:focusable="true"
     android:focusableInTouchMode="true"  />
</LinearLayout>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜