Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.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-游戏崩溃,OutOfMemory异常_Java_Android_View_Crash_Android Canvas - Fatal编程技术网

Java-游戏崩溃,OutOfMemory异常

Java-游戏崩溃,OutOfMemory异常,java,android,view,crash,android-canvas,Java,Android,View,Crash,Android Canvas,我有一个游戏,有两个简单的屏幕绘制画布和视图。一个用于我的游戏,一个用于输屏。当我输了并且想回到游戏时,我的游戏崩溃并抛出以下代码的越界异常并崩溃: pauseBackground = BitmapFactory.decodeResource(getResources(), R.drawable.pausebackground); pausedText = BitmapFactory.decodeResource(getResources(), R.drawable.play);

我有一个游戏,有两个简单的屏幕绘制画布和视图。一个用于我的游戏,一个用于输屏。当我输了并且想回到游戏时,我的游戏崩溃并抛出以下代码的越界异常并崩溃:

    pauseBackground = BitmapFactory.decodeResource(getResources(), R.drawable.pausebackground);
    pausedText = BitmapFactory.decodeResource(getResources(), R.drawable.play);
    cont = BitmapFactory.decodeResource(getResources(), R.drawable.cont);
    box = BitmapFactory.decodeResource(getResources(), R.drawable.box);
奇怪的是,我实际上只见过几次这种错误,似乎无法模仿它。当我现在在模拟器上运行应用程序时,它运行良好,不会崩溃。但当我把它放在手机上时,它崩溃了

这就是我改变观点的方式:

    View playView = new PlayScreen(getContext());
    ViewGroup parent = (ViewGroup) getParent();

    parent.addView(playView);
    parent.removeView(this);
    parent.setBackgroundResource(R.drawable.background);

为什么要这样做?我的头脑被记忆错误或边界外的感觉震晕了?如果是前者,我很确定它是,那么它可以是这些的任意组合:图像太大,你持有位图的引用而没有回收它们,你没有在必要时适当地对更大的文件进行降采样,等等,但是没有看到关于你的项目的更多代码和信息,很难告诉您问题的最大原因是什么。如何回收它们?Bitmap.recycle当不再需要时,Bitmap是位图对象的实例,您能解释一下为什么这会有帮助吗?此外,这不会改变蜂窝设备之前的任何情况。
manifest file in this code use:-

 <application
        android:allowBackup="true"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name"
        android:largeHeap="true"                   //This line add in application tag