技术CTO-关注编程入门知识,提供编程入门教程

您的位置: 首页 > 移动开发 > android > 正文

运行时出现unfortunately *** has stopped了,求解! ...

来源: 技术CTO 阅读:

新手,第一天实战,运行时出现:运行时出现unfortunately *** has stopped了,求解!
这MainActivity:
package com.mingrisoft;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
private boolean flag=true;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LinearLayout ll=(LinearLayout)findViewById(R.id.ll); //获取布局文件中添加的线性布局管理器
       
        
        final AnimationDrawable anim=(AnimationDrawable)ll.getBackground(); //获取AnimationDrawable对象
        //为线性布局管理器添加单击事件监听器
        ll.setOnClickListener(new OnClickListener() {
   
   @Override
   public void onClick(View v) {
    if(flag){
     anim.start(); //开始播放动画
     flag=false;
    }else{
     anim.stop(); //停止播放动画
     flag=true;
    }
   }
  });
    }
}

这个是log

06-30 06:43:09.230: D/dalvikvm(902): GC_FOR_ALLOC freed 53K, 5% free 2785K/2912K, paused 205ms, total 208ms
06-30 06:43:09.270: I/dalvikvm-heap(902): Grow heap (frag case) to 10.698MB for 8294416-byte allocation
06-30 06:43:09.420: D/dalvikvm(902): GC_FOR_ALLOC freed 2K, 2% free 10883K/11016K, paused 143ms, total 143ms
06-30 06:43:14.330: D/AndroidRuntime(902): Shutting down VM
06-30 06:43:14.330: W/dalvikvm(902): threadid=1: thread exiting with uncaught exception (group=0xb2a92ba8)
06-30 06:43:14.350: E/AndroidRuntime(902): FATAL EXCEPTION: main
06-30 06:43:14.350: E/AndroidRuntime(902): Process: com.mingrisoft, PID: 902
06-30 06:43:14.350: E/AndroidRuntime(902): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mingrisoft/com.mingrisoft.MainActivity}: java.lang.ClassCastException: android.graphics.drawable.BitmapDrawable cannot be cast to android.graphics.drawable.AnimationDrawable
06-30 06:43:14.350: E/AndroidRuntime(902):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
06-30 06:43:14.350: E/AndroidRuntime(902):         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
06-30 06:43:14.350: E/AndroidRuntime(902):         at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-30 06:43:14.350: E/AndroidRuntime(902):         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-30 06:43:14.350: E/AndroidRuntime(902):         at android.os.Handler.dispatchMessage(Handler.java:102)
06-30 06:43:14.350: E/AndroidRuntime(902):         at android.os.Looper.loop(Looper.java:136)
06-30 06:43:14.350: E/AndroidRuntime(902):         at android.app.ActivityThread.main(ActivityThread.java:5017)
06-30 06:43:14.350: E/AndroidRuntime(902):         at java.lang.reflect.Method.invokeNative(Native Method)
06-30 06:43:14.350: E/AndroidRuntime(902):         at java.lang.reflect.Method.invoke(Method.java:515)
06-30 06:43:14.350: E/AndroidRuntime(902):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-30 06:43:14.350: E/AndroidRuntime(902):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-30 06:43:14.350: E/AndroidRuntime(902):         at dalvik.system.NativeStart.main(Native Method)
06-30 06:43:14.350: E/AndroidRuntime(902): Caused by: java.lang.ClassCastException: android.graphics.drawable.BitmapDrawable cannot be cast to android.graphics.drawable.AnimationDrawable
06-30 06:43:14.350: E/AndroidRuntime(902):         at com.mingrisoft.MainActivity.onCreate(MainActivity.java:21)
06-30 06:43:14.350: E/AndroidRuntime(902):         at android.app.Activity.performCreate(Activity.java:5231)
06-30 06:43:14.350: E/AndroidRuntime(902):         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-30 06:43:14.350: E/AndroidRuntime(902):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
06-30 06:43:14.350: E/AndroidRuntime(902):         ... 11 more
06-30 06:45:07.260: I/Process(902): Sending signal. PID: 902 SIG: 9
06-30 06:45:44.300: D/dalvikvm(1302): GC_FOR_ALLOC freed 49K, 5% free 2785K/2908K, paused 44ms, total 45ms
06-30 06:45:44.300: I/dalvikvm-heap(1302): Grow heap (frag case) to 10.698MB for 8294416-byte allocation
06-30 06:45:44.760: D/dalvikvm(1302): GC_FOR_ALLOC freed 2K, 2% free 10883K/11012K, paused 53ms, total 54ms
06-30 06:45:45.900: D/AndroidRuntime(1302): Shutting down VM
06-30 06:45:45.900: W/dalvikvm(1302): threadid=1: thread exiting with uncaught exception (group=0xb2a92ba8)
06-30 06:45:45.910: E/AndroidRuntime(1302): FATAL EXCEPTION: main
06-30 06:45:45.910: E/AndroidRuntime(1302): Process: com.mingrisoft, PID: 1302
06-30 06:45:45.910: E/AndroidRuntime(1302): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mingrisoft/com.mingrisoft.MainActivity}: java.lang.ClassCastException: android.graphics.drawable.BitmapDrawable cannot be cast to android.graphics.drawable.AnimationDrawable
06-30 06:45:45.910: E/AndroidRuntime(1302):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
06-30 06:45:45.910: E/AndroidRuntime(1302):         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
06-30 06:45:45.910: E/AndroidRuntime(1302):         at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-30 06:45:45.910: E/AndroidRuntime(1302):         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-30 06:45:45.910: E/AndroidRuntime(1302):         at android.os.Handler.dispatchMessage(Handler.java:102)
06-30 06:45:45.910: E/AndroidRuntime(1302):         at android.os.Looper.loop(Looper.java:136)
06-30 06:45:45.910: E/AndroidRuntime(1302):         at android.app.ActivityThread.main(ActivityThread.java:5017)
06-30 06:45:45.910: E/AndroidRuntime(1302):         at java.lang.reflect.Method.invokeNative(Native Method)
06-30 06:45:45.910: E/AndroidRuntime(1302):         at java.lang.reflect.Method.invoke(Method.java:515)
06-30 06:45:45.910: E/AndroidRuntime(1302):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-30 06:45:45.910: E/AndroidRuntime(1302):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-30 06:45:45.910: E/AndroidRuntime(1302):         at dalvik.system.NativeStart.main(Native Method)
06-30 06:45:45.910: E/AndroidRuntime(1302): Caused by: java.lang.ClassCastException: android.graphics.drawable.BitmapDrawable cannot be cast to android.graphics.drawable.AnimationDrawable
06-30 06:45:45.910: E/AndroidRuntime(1302):         at com.mingrisoft.MainActivity.onCreate(MainActivity.java:19)
06-30 06:45:45.910: E/AndroidRuntime(1302):         at android.app.Activity.performCreate(Activity.java:5231)
06-30 06:45:45.910: E/AndroidRuntime(1302):         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-30 06:45:45.910: E/AndroidRuntime(1302):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
06-30 06:45:45.910: E/AndroidRuntime(1302):         ... 11 more
06-30 06:46:30.070: I/Process(1302): Sending signal. PID: 1302 SIG: 9

android.graphics.drawable.BitmapDrawable cannot be cast to android.graphics.drawable.AnimationDrawable
是指BitmapDrawable对象不能转换为AnimationDrawable 对象?
是什么意思?
哪句代码出了问题?
是指BitmapDrawable对象不能转换为AnimationDrawable 对象?
是什么意思?
不好意思,我太菜了!

^_^ 如果您热爱技术、热爱编程,想与更多的朋友一起交流学习,欢迎加入本站官方QQ群:345733473 ^_^