Extending the Drawable Class

All your problems with Audio, Video and Images.

Extending the Drawable Class

Postby cnatale37 » Fri May 22, 2009 6:12 pm

Hello,

I'm fairly new to Android development, and am having trouble wrapping my head around a few things concerning the Drawable class.

First, I see in Google's documentation that the Drawable's draw method has an abstract modifier. However, their Lunar Lander source code uses Drawable types to draw images on the screen. If draw is abstract in a Drawable, how is it being drawn to the screen?

The second problem seems to relate to the first. I've written a class that extends Drawable into a Sprite class with some additional properties and methods for a video game I'm working on. When I was loading an image resource into a Drawable instance, everything was working fine. However, when I tried to convert the Drawable into a Sprite, like so:

mSpriteImage = (Sprite) context.getResources().getDrawable(R.drawable.testImage);

...I get a runtime ClassCastException. I don't understand why there's a problem casting this Drawable to a class that extends from Drawable.

Thanks for All Help.
cnatale37
Freshman
Freshman
 
Posts: 2
Joined: Fri May 22, 2009 6:00 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 15 guests