Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java (仅有时)启动Android应用程序时发生OutOfMemoryError_Java_Android_Out Of Memory - Fatal编程技术网

Java (仅有时)启动Android应用程序时发生OutOfMemoryError

Java (仅有时)启动Android应用程序时发生OutOfMemoryError,java,android,out-of-memory,Java,Android,Out Of Memory,我几乎完成了我的第一个android小游戏。但现在我遇到了一个问题:有时,当我按下home(主页)按钮并想重新启动游戏时,它会崩溃并导致OutOfMemoryError——但不是每次都是如此。我尝试在onsurfacedestromed()方法中回收图像,但没有改变。我还将android:launchMode=“singleTask”添加到我的manifest文件中的activity元素中-仍然存在问题 这是堆栈跟踪: 04-13 07:28:24.227: E/AndroidRuntime(1

我几乎完成了我的第一个android小游戏。但现在我遇到了一个问题:有时,当我按下home(主页)按钮并想重新启动游戏时,它会崩溃并导致
OutOfMemoryError
——但不是每次都是如此。我尝试在
onsurfacedestromed()
方法中回收图像,但没有改变。我还将
android:launchMode=“singleTask”
添加到我的
manifest
文件中的activity元素中-仍然存在问题

这是堆栈跟踪:

04-13 07:28:24.227: E/AndroidRuntime(1804): FATAL EXCEPTION: main
04-13 07:28:24.227: E/AndroidRuntime(1804): Process: de.lucid.mygame, PID: 1804
04-13 07:28:24.227: E/AndroidRuntime(1804): java.lang.OutOfMemoryError
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:575)
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:410)
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:433)
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:463)
04-13 07:28:24.227: E/AndroidRuntime(1804): at de.lucid.mygame.views.PlayView$GameThread.<init>(PlayView.java:96)
04-13 07:28:24.227: E/AndroidRuntime(1804): at de.lucid.mygame.views.PlayView.restart(PlayView.java:346)
04-13 07:28:24.227: E/AndroidRuntime(1804): at de.lucid.mygame.activities.PlayActivity.onStart(PlayActivity.java:61)
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.app.Activity.performStart(Activity.java:5253)
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.app.Activity.performRestart(Activity.java:5309)
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.app.Activity.performResume(Activity.java:5314)
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2759)
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2798)
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1439)
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.os.Handler.dispatchMessage(Handler.java:102)
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.os.Looper.loop(Looper.java:137)
04-13 07:28:24.227: E/AndroidRuntime(1804): at android.app.ActivityThread.main(ActivityThread.java:4998)
04-13 07:28:24.227: E/AndroidRuntime(1804): at java.lang.reflect.Method.invokeNative(Native Method)
04-13 07:28:24.227: E/AndroidRuntime(1804): at java.lang.reflect.Method.invoke(Method.java:515)
04-13 07:28:24.227: E/AndroidRuntime(1804): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
04-13 07:28:24.227: E/AndroidRuntime(1804): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
04-13 07:28:24.227: E/AndroidRuntime(1804): at dalvik.system.NativeStart.main(Native Method)
04-13 07:28:24.227:E/AndroidRuntime(1804):致命异常:main
04-13 07:28:24.227:E/AndroidRuntime(1804):进程:de.lucid.mygame,PID:1804
04-13 07:28:24.227:E/AndroidRuntime(1804):java.lang.OutOfMemoryError
04-13 07:28:24.227:E/AndroidRuntime(1804):在android.graphics.BitmapFactory.NativeDeacSet(本机方法)
04-13 07:28:24.227:E/AndroidRuntime(1804):在android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:575)
04-13 07:28:24.227:E/AndroidRuntime(1804):在android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:410)
04-13 07:28:24.227:E/AndroidRuntime(1804):在android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:433)上
04-13 07:28:24.227:E/AndroidRuntime(1804):在android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:463)上
04-13 07:28:24.227:E/AndroidRuntime(1804):在de.lucid.mygame.views.PlayView$GameThread。(PlayView.java:96)
04-13 07:28:24.227:E/AndroidRuntime(1804):在de.lucid.mygame.views.PlayView.restart(PlayView.java:346)
04-13 07:28:24.227:E/AndroidRuntime(1804):在de.lucid.mygame.activities.PlayActivity.onStart(PlayActivity.java:61)
04-13 07:28:24.227:E/AndroidRuntime(1804):在android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)上
04-13 07:28:24.227:E/AndroidRuntime(1804):在android.app.Activity.performStart(Activity.java:5253)上
04-13 07:28:24.227:E/AndroidRuntime(1804):在android.app.Activity.performRestart(Activity.java:5309)
04-13 07:28:24.227:E/AndroidRuntime(1804):在android.app.Activity.performResume(Activity.java:5314)
04-13 07:28:24.227:E/AndroidRuntime(1804):在android.app.ActivityThread.performResumeActivity(ActivityThread.java:2759)
04-13 07:28:24.227:E/AndroidRuntime(1804):在android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2798)
04-13 07:28:24.227:E/AndroidRuntime(1804):在android.app.ActivityThread$H.handleMessage(ActivityThread.java:1439)
04-13 07:28:24.227:E/AndroidRuntime(1804):在android.os.Handler.dispatchMessage(Handler.java:102)上
04-13 07:28:24.227:E/AndroidRuntime(1804):在android.os.Looper.loop(Looper.java:137)
04-13 07:28:24.227:E/AndroidRuntime(1804):位于android.app.ActivityThread.main(ActivityThread.java:4998)
04-13 07:28:24.227:E/AndroidRuntime(1804):位于java.lang.reflect.Method.Invokenactive(本机方法)
04-13 07:28:24.227:E/AndroidRuntime(1804):位于java.lang.reflect.Method.invoke(Method.java:515)
04-13 07:28:24.227:E/AndroidRuntime(1804):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
04-13 07:28:24.227:E/AndroidRuntime(1804):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
04-13 07:28:24.227:E/AndroidRuntime(1804):在dalvik.system.NativeStart.main(本机方法)
有人能帮我吗


谢谢:)

您如何加载图像?你把这些图像放在任何物体里吗?如下所示:backgroundImg=BitmapFactory.decodeResource(context.getResources(),R.drawable.bg)。。。在onSurfaceDestroyed()-方法中,我为每个位图对象调用recycle()-方法。。。