[英]Why does my app crash when I open it for the second time?
When I install my app on my device through Android Studio, everything is ok, but when I close the app, and try to reopen it, the app crash.当我通过 Android Studio 在我的设备上安装我的应用程序时,一切正常,但是当我关闭应用程序并尝试重新打开它时,应用程序崩溃了。 I have also tried to do a new project with the same project but everytime I obtain the same problem.
我也尝试用同一个项目做一个新项目,但每次我都遇到同样的问题。 I don't use a complicated code but don't knwow why this happens.
我不使用复杂的代码,但不知道为什么会发生这种情况。
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 9223212 byte allocation with 5451732 free bytes and 5MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:741)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:562)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1014)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:3702)
at android.content.res.Resources.loadDrawable(Resources.java:3575)
at android.content.res.TypedArray.getDrawable(TypedArray.java:750)
at com.blunderer.materialdesignlibrary.views.CardView.<init>(CardView.java:58)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:130)
at it.quotidianiitaliani.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:6221)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
OutOfMemoryError is the most common problem occur in android while especially dealing with bitmaps. OutOfMemoryError 是android 中最常见的问题,尤其是处理位图时。 This error is thrown by the Java Virtual Machine (JVM) when an object cannot be allocated due to lack of memory space and also, the garbage collector cannot free some space.
当由于内存空间不足而无法分配对象并且垃圾收集器无法释放一些空间时,Java 虚拟机 (JVM) 会抛出此错误。
I think you should read some at Androids Developer page, specially here: http://developer.android.com/training/displaying-bitmaps/index.html我认为您应该在 Android 开发人员页面上阅读一些内容,特别是这里: http : //developer.android.com/training/displaying-bitmaps/index.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.