内存错误的Android位图工厂的java.lang.out
A've试图回收位图和我在google上发现的所有其他内容,但问题仍然存在......这是我的代码:
final SampleView mainPogled = new SampleView(this);
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Config.RGB_565;
options.inDither = true;
pozadinap = BitmapFactory.decodeResource(getResources(), R.drawable.nivoapozadina, options);
playButtonp = BitmapFactory.decodeResource(getResources(), R.drawable.play, options);
pozadina = Bitmap.createScaledBitmap(pozadinap, s_width, s_height, false);
playButton = Bitmap.createBitmap(playButtonp);
在和我画位图到一个画布..
这是错误:
06-14 14:21:16.452:W / dalvikvm(1930):threadid = 1:线程退出与未捕获的异常(group = 0xb1ab7ba8)06-14 14:21:16.482:E / AndroidRuntime(1930):致命异常:main 06-14 14:21:16.482:E / AndroidRuntime(1930):进程:com.hv.snake,PID:1930年6月14日14:21:16.482:E / AndroidRuntime(1930):java.lang.OutOfMemoryError 06- 14 14:21:16.482:E / AndroidRuntime(1930):在android.graphics.Bitmap.nativeCreate(本地方法)06-14 14:21:16.482:E / AndroidRuntime(1930):at android.graphics.Bitmap.createBitmap (Bitmap.java:809)06-14 14:21:16.482:E / AndroidRuntime(1930):at android.graphics.Bitmap.createBitmap(Bitmap.java:786)06-14 14:21:16.482:E / AndroidRuntime (1930):at android.graphics.Bitmap.createBitmap(Bitmap.java:718)06-14 14:21:16.482:E / AndroidRuntime(1930):at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:594) 06-14 14:21:16.482:E / AndroidRuntime(1930):at com.hv.snake.MainMenu.onCreate(MainMenu.java:56)06-14 14:21:16.482:E / AndroidRuntime(1930):at android.app.Activity.perfo rmCreate(Activity.java:5231)06-14 14:21:16.482:E / AndroidRuntime(1930):at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)06-14 14:21:16.482:E / AndroidRuntime(1930):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)06-14 14:21:16.482:E / AndroidRuntime(1930):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245 )06-14 14:21:16.482:E / AndroidRuntime(1930):at android.app.ActivityThread.access $ 800(ActivityThread.java:135)06-14 14:21:16.482:E / AndroidRuntime(1930):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1196)06-14 14:21:16.482:E / AndroidRuntime(1930):at android.os.Handler.dispatchMessage(Handler.java:102)06-14 14:21:16.482:E / AndroidRuntime(1930):在android.os.Looper.loop(Looper.java:136)06-14 14:21:16.482:E / AndroidRuntime(1930):at android.app.ActivityThread .main(ActivityThread.java:5017)06-14 14:21:16.482:E / AndroidRuntime(1930):at java.lang.reflect.Method.invokeNative(Na tive Method)06-14 14:21:16.482:E / AndroidRuntime(1930):at java.lang.reflect.Method.invoke(Method.java:515)06-14 14:21:16.482:E / AndroidRuntime(1930 ):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779)06-14 14:21:16.482:E / AndroidRuntime(1930):at com.android.internal.os.ZygoteInit。 main(ZygoteInit.java:595)06-14 14:21:16.482:E / AndroidRuntime(1930):at dalvik.system.NativeStart.main(Native Method)
我在2天后找到了解决方案......这篇文章帮了我很多。
在onDestroy()方法中,首先回收活动中的所有位图,然后将它们全部设置为null,然后调用System.gc()。 例如
public void onDestroy() {
super.onDestroy();
background.recycle();
background = null;
System.gc();
}
我希望这会帮助某人。
链接地址: http://www.djcxy.com/p/33657.html上一篇: java.lang.out of memory error Android Bitmap Factory
下一篇: Out of memory error when inflating simple xml layout in android