在一些设备上强制关闭startanimation仿真器+ logcat

时间:2014-08-21 09:38:59

标签: android animation forceclose

我的应用程序有一个欢迎动画,动画类型是帧动画,但在某些设备中,如sony z1,并且总是在模拟器上它会导致强制关闭,但是当我删除该活动应用程序正常运行时。

动画代码是这样的:

public class welcome extends Activity {
 @Override
  protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.welcome);
     ImageView iv_anim=(ImageView) findViewById(R.id.img_anim_main);
       iv_anim.setBackgroundResource(R.drawable.animation_main);
      AnimationDrawable animmain=(AnimationDrawable) iv_anim.getBackground();
      animmain.start();
    MediaPlayer mplayer=MediaPlayer.create(this, R.raw.airplane);
    mplayer.start();
       Timer timer=new Timer();
       timer.schedule(new TimerTask() {

        @Override
        public void run() {

            Intent intent=new Intent(welcome.this, MainActivity.class);
            startActivity(intent);
            finish();
        }
    }, 3625);
    super.onCreate(savedInstanceState);
}
 }

AND LOGCAT是这样的:

08-22 06:09:48.770: I/dalvikvm(603):   at dalvik.system.NativeStart.main(Native Method)
08-22 06:09:48.770: D/skia(603): --- decoder->decode returned false
08-22 06:09:48.820: D/AndroidRuntime(603): Shutting down VM
08-22 06:09:48.820: W/dalvikvm(603): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
08-22 06:09:48.990: E/AndroidRuntime(603): FATAL EXCEPTION: main
08-22 06:09:48.990: E/AndroidRuntime(603): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.politic/com.example.politic.welcome}: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.os.Looper.loop(Looper.java:137)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.app.ActivityThread.main(ActivityThread.java:4340)
08-22 06:09:48.990: E/AndroidRuntime(603):  at java.lang.reflect.Method.invokeNative(Native Method)
08-22 06:09:48.990: E/AndroidRuntime(603):  at java.lang.reflect.Method.invoke(Method.java:511)
08-22 06:09:48.990: E/AndroidRuntime(603):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-22 06:09:48.990: E/AndroidRuntime(603):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-22 06:09:48.990: E/AndroidRuntime(603):  at dalvik.system.NativeStart.main(Native Method)
08-22 06:09:48.990: E/AndroidRuntime(603): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.view.LayoutInflater.createView(LayoutInflater.java:606)
08-22 06:09:48.990: E/AndroidRuntime(603):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-22 06:09:48.990: E/AndroidRuntime(603):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.app.Activity.setContentView(Activity.java:1835)
08-22 06:09:48.990: E/AndroidRuntime(603):  at com.example.politic.welcome.onCreate(welcome.java:20)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.app.Activity.performCreate(Activity.java:4465)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
08-22 06:09:48.990: E/AndroidRuntime(603):  ... 11 more
08-22 06:09:48.990: E/AndroidRuntime(603): Caused by: java.lang.reflect.InvocationTargetException
08-22 06:09:48.990: E/AndroidRuntime(603):  at java.lang.reflect.Constructor.constructNative(Native Method)
08-22 06:09:48.990: E/AndroidRuntime(603):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.view.LayoutInflater.createView(LayoutInflater.java:586)
08-22 06:09:48.990: E/AndroidRuntime(603):  ... 24 more
08-22 06:09:48.990: E/AndroidRuntime(603): Caused by: java.lang.OutOfMemoryError
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.content.res.Resources.loadDrawable(Resources.java:1937)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.content.res.Resources.getDrawable(Resources.java:664)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:270)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:867)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.graphics.drawable.Drawable.createFromXml(Drawable.java:804)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.content.res.Resources.loadDrawable(Resources.java:1922)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.view.View.<init>(View.java:2780)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.widget.ImageView.<init>(ImageView.java:113)
08-22 06:09:48.990: E/AndroidRuntime(603):  at android.widget.ImageView.<init>(ImageView.java:109)
08-22 06:09:48.990: E/AndroidRuntime(603):  ... 27 more

2 个答案:

答案 0 :(得分:0)

原因似乎是行

08-22 06:09:48.990: E/AndroidRuntime(603): Caused by: java.lang.OutOfMemoryError
您的异常堆栈跟踪的

。您的动画可能包含太多占用太多内存的帧。确认您可能要调查R.drawable.animation_main的XML资源。

答案 1 :(得分:0)

在这里,您获得Out of Memory error,这意味着您想要制作动画的图像可能是大尺寸图像。因此,需要时间来制作并强制关闭您的应用。

您可以在将图像转换为位图或使用小尺寸图像或解码该图像文件后调整图像大小。

另一件事是调用此行

 super.onCreate(savedInstanceState);

之前

 setContentView(R.layout.welcome);