I want to start an animation. I have my animation defined in res/drawable:

<animation-list android:id="@+id/flying_around" android:oneshot="false">
<item android:drawable="@drawable/ricky_flames" android:duration="50" />
<item android:drawable="@drawable/ricky_flames_1" android:duration="50" />
<item android:drawable="@drawable/ricky_flames_2" android:duration="50" />
<item android:drawable="@drawable/ricky_flames_3" android:duration="50" />
<item android:drawable="@drawable/ricky_flames_4" android:duration="50" />
</animation-list>

and I try to start this animation in the onCreate method after I have clicked through text a few times (this is in a setOnClickListener function for a textView):

tutorialText.setVisibility(View.GONE);
imageView.setImageDrawable(getResources().getDrawable(R.drawable.ricky_flying_animation));
startEngine = (AnimationDrawable) imageView.getDrawable();   
startEngine.start();

Here is the error:

java.lang.ClassCastException: android.graphics.drawable.StateListDrawable cannot be cast to android.graphics.drawable.AnimationDrawable

0 Answers