所以我有这个可绘制的动画列表,它是一系列图像。
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true">
<item android:drawable="@drawable/image1" android:duration="2000" />
<item android:drawable="@drawable/image2" android:duration="2000" />
</animation-list>
现在的问题是,有时我会收到此错误并导致我的应用程序强制关闭:
java.lang.ClassCastException: android.graphics.drawable.BitmapDrawable cannot be cast to android.graphics.drawable.AnimationDrawable
at com.example.try.drawable.AnimationClass.run(AnimationClass.java:80)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
这是我在 AnimationClass 中指出的内容:
public void run() {
((AnimationDrawable) mImages.getDrawable()).start();
}
mImages 变量是我的 xml 中的变量。我向用户展示它们就像一个 splashImage 一样。问题是我有时会收到此错误,但我不知道它是如何发生的。
PS 我故意更改了一些变量名和包名,但希望代码仍然和我一样清晰。