Problem on loading AnimationDrawable from xml

Put your problem here if it does not fit any of the other categories.

Postby rmeph » Fri Jan 25, 2008 2:57 pm

i used xml file for set frame background in res/drawable

"skin.xml"
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4.  <frames id="selected" oneshot="false">
  5.  
  6.     <frame drawable="@drawable/image_1" duration="50" />
  7.  
  8.     <frame drawable="@drawable/image_2" duration="50" />
  9.  
  10.     <frame drawable="@drawable/image_3" duration="50" />
  11.  
  12.     <frame drawable="@drawable/image_4" duration="50" />
  13.  
  14.   </resource>
  15.  
  16.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


and java code
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public View getView(int position, View convertView, ViewGroup parent) {
  3.  
  4.  
  5.  
  6. ImageView i =(ImageView)findViewById(R.id.img);
  7.  
  8.  i.setBackground(R.drawable.skin);
  9.  
  10. AnimationDrawable frameAnimation = (AnimationDrawable) i.getBackground();
  11.  
  12. frameAnimation.start();
  13.  
  14. return i;
  15.  
  16. }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


but it's application error

res/drawable/skin.xml from drawable resource ID #0x7fo400

Can anybody advise how to solve the problem ? :roll:
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Top

Postby plusminus » Fri Jan 25, 2008 3:39 pm

Hello rmeph,

your code looks almost the same as Google AnimationDrawable Example. I cannot detect any syntax difference...

Perhaps your R.java is not being correctly updated :? :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby rmeph » Fri Jan 25, 2008 3:53 pm

not it's updated.......in R.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  public static final class drawable {
  3.  
  4.         public static final int a=0x7f020000;
  5.  
  6.         public static final int abt=0x7f020001;
  7.  
  8.         public static final int b=0x7f020002;
  9.  
  10.         public static final int ct=0x7f020003;
  11.  
  12.         public static final int exit=0x7f020004;
  13.  
  14.         public static final int fav=0x7f020005;
  15.  
  16.         public static final int help=0x7f020006;
  17.  
  18.         public static final int icon=0x7f020007;
  19.  
  20.         public static final int image_1=0x7f020008;
  21.  
  22.         public static final int image_2=0x7f020009;
  23.  
  24.         public static final int image_3=0x7f02000a;
  25.  
  26.         public static final int image_4=0x7f02000b;
  27.  
  28.         public static final int ph=0x7f02000c;
  29.  
  30.         public static final int shape_1=0x7f02000d;
  31.  
  32.         public static final int shape_2=0x7f02000e;
  33.  
  34.         public static final int skin=0x7f02000f;
  35.  
  36.         public static final int xs2=0x7f020010;
  37.  
  38.     }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

how solved it?
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby plusminus » Fri Jan 25, 2008 4:01 pm

Hello rmeph,

your R.java above shows:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ...
  2.  
  3. public static final int skin=0x7f02000f;
  4.  
  5. ...
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

but as you said, your error showed: "resource ID #0x7f0400".

Perhaps a build-issue.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby rmeph » Sat Jan 26, 2008 7:37 am

actually i write wrong .....it's show error "res/drawable/skin.xml from drawable resource ID #0x7f02000f"
I haven't yet found what is the problem.
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby plusminus » Sat Jan 26, 2008 10:16 am

Hello rmeph,

Many others have the same problem.
It seems not to be implemented already, according to what I found in the Google Groups:
Hi,

although the emulator displays a Resources$NotFoundException, the real problem is that "frames" is not a valid XML tag for drawables. Looking at the DDMS log reveals that the NotFoundException is caused by:

E/AndroidRuntime(553): Caused by:
org.xmlpull.v1.XmlPullParserException:
Binary XML file line #1: invalid drawable tag frames

It seems that reading drawable animations is not implemented properly (if at all) or the documentation is wrong.

Cheers,
F


Either way, let's hope they fix it in the next release.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby rmeph » Sat Jan 26, 2008 10:56 am

thanks you for reply.........

i want change colors of frame blackground between some time intervals....how to do that?????
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby plusminus » Sat Jan 26, 2008 11:04 am

Hello rmeph,

perhaps a Thread and a Handler like done in the :src: PizzaTimer-Tutorial fits your needs.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby rmeph » Sat Jan 26, 2008 11:25 am

but i don't press any key for time counter.....time is runing in background....
i want when frame display then color is red and after 5 second color is pink and after 5 second color is................................
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby plusminus » Sat Jan 26, 2008 11:59 am

Hello rmeph,

of course you need to adapt the code. Somewhat like this code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.      class myRunner implements Runnable{
  2.  
  3.           // @Override
  4.  
  5.           public void run() {
  6.  
  7.                while(!Thread.currentThread().isInterrupted()){
  8.  
  9.                     Message m = new Message();
  10.  
  11.                     m.what = myActivity.CHANGEBACKGROUNDCOLOR;
  12.  
  13.                     myActivity.this.myAnimationHandler.sendMessage(m);
  14.  
  15.                     try {
  16.  
  17.                          Thread.sleep(5000);
  18.  
  19.                     } catch (InterruptedException e) {
  20.  
  21.                          Thread.currentThread().interrupt();
  22.  
  23.                     }
  24.  
  25.                }
  26.  
  27.           }
  28.  
  29.     }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4

And the Handler receiving the Messages from above:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.      Handler myAnimationHandler= new Handler(){
  2.  
  3.           /** Gets called on every message that is received */
  4.  
  5.           // @Override
  6.  
  7.           public void handleMessage(Message msg) {
  8.  
  9.                switch (msg.what) {
  10.  
  11.                     case myActivity.CHANGEBACKGROUNDCOLOR:
  12.  
  13.                          // Change your background color HERE !!
  14.  
  15.  
  16.  
  17.                          myView.invalidate();
  18.  
  19.                          break;
  20.  
  21.                }
  22.  
  23.                super.handleMessage(msg);
  24.  
  25.           }
  26.  
  27.      };
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


Hope I could help you.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby rmeph » Sun Jan 27, 2008 11:39 am

thnaks you for reply...i will try that may be it's working...
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby rmeph » Mon Jan 28, 2008 9:55 am

In code i used ImageView is static ....when i used object of ImageView in handler Class

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. i.setBackground(R.drawable.frame3);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


it's cannot display anything....how to solved it?
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby plusminus » Mon Jan 28, 2008 3:09 pm

Hello rmeph,

its hard to understand what your current code is.
Please post some lines, that we can detect your problem more easy.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby rmeph » Wed Jan 30, 2008 7:03 am

i used in getView
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public View getView(int position, View convertView, ViewGroup parent) {
  2.  
  3.  
  4.  
  5.  i =(ImageView)findViewById(R.id.img);
  6.  
  7.  i.setBackground(R.drawable.frame);
  8.  
  9. return i;
  10.  
  11. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


when change background in handler i used

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Handler myAnimationHandler= new Handler(){
  2.  
  3.           /** Gets called on every message that is received */
  4.  
  5.           // @Override
  6.  
  7.           public void handleMessage(Message msg) {
  8.  
  9.                switch (msg.what) {
  10.  
  11.                     case myActivity.CHANGEBACKGROUNDCOLOR:
  12.  
  13.                          // Change your background color HERE !!
  14.  
  15.                       i.setBackground(R.drawable.frame3);
  16.  
  17.                         i.invalidate();
  18.  
  19.                          break;
  20.  
  21.                }
  22.  
  23.                super.handleMessage(msg);
  24.  
  25.           }
  26.  
  27.      };
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


but it's don't change background....
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby plusminus » Wed Jan 30, 2008 10:56 am

Hello rmeph,

so the first i.setBackground() in getView() works, but not in the Handler :?:

When you debug your app, is handleMessage() of your ever Handler called :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top
Next

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 26 guests