当前位置: 代码迷 >> Android >> 运行时出现unfortunately * has stopped了,求解! .该怎么解决
  详细解决方案

运行时出现unfortunately * has stopped了,求解! .该怎么解决

热度:65   发布时间:2016-04-28 04:41:53.0
运行时出现unfortunately *** has stopped了,求解! ...
新手,第一天实战,运行时出现:运行时出现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)
  相关解决方案