Saturday, September 12, 2009

ERROR Error parsing XML file: Unbound prefix

In my last days I've been playing around with Android SDK making a little game. Found out the SDK is very poor in documentation and even some examples have errors.
I ran into the "Unbound prefix" error while trying to make a frame by frame animation. The example showed something like this:

 <?xml version="1.0" encoding="UTF-8"?>
 <animation-list   android:id="selected"  android:oneshot="false">
     <item android:drawable="@drawable/ballmove" android:duration="150"/>
     <item android:drawable="@drawable/ballmove2" android:duration="150"/>    
     <item android:drawable="@drawable/ballmove3" android:duration="150"/> 
</animation-list>  

but if you tryed it yourself you surely found out it isn't working.

The way to solve this stupid error is to add
xmlns:android="http://schemas.android.com/apk/res/android"
as the first attribute for the animation-list tag.

6 comments:

  1. hey alexandu,
    i've added the xmlns:android as 1st attribute of animation tag,now it's givng an error:string type not allowed with id (android:id)in animation -tag,can u help me out

    ReplyDelete
  2. Well, you don't need an android:id attribute in your animations tag. The android:id attribute is needed when you try to inflate a View object from an XML. When using animations you will refer to it by R.drawable.youranimation (if it's a frame-by-frame animation) or R.anim.youranimation (where youranimation is the name of your xml file).
    E.g.:
    Animation a = AnimationUtils.loadAnimation(yourview.getContext(), R.anim.youranimation);
    yourview.setAnimation(a);
    a.start();

    ReplyDelete
  3. thnx a loat alex 4 for quick reply ;)
    that worked,i also tried d same without xml file using the function,
    (ad=new animationdrawable).addFrame(getresources().getDrawable()) then call ad.start()

    now the same thing which i want is to read the images from content provider instead of taking from res/drawable.like I have cursor object which is obtained from quering images to MediaStore.images.thumbnails.Extranal_Uri(reading from sd card),Now i want to navigate the cursor,and get the image one by one and thus ve a frame animation,

    so can u tell me is there any methods how to implement frameaniamtion for this....

    ReplyDelete
  4. I think you're doing an overkill. From what I understand the Gallery view would fix all your problems. Frame by frame animations are designed for static content and you need a designer. If gallery view it's not enough you can make your own view and use Scale/Translate/Alpha/Rotate animations.

    ReplyDelete
  5. hi,

    i also have same problem,
    error: Error parsing XML: unbound prefix

    and this error was overcome by write
    xmlns:android="http://schemas.android.com/apk/res/android"

    but still i got same problem
    after add android in xmlns:=""http://schemas.android.com/apk/res/android"
    "
    please any one can help me

    ReplyDelete