6

java.lang.OutOfMemoryError在使用位图显示大图像时得到了。
为了调整位图的大小,我参考了以下链接Save Bitmap 和 BitmapFactory.decodeFile

我的logcat如下:

FATAL EXCEPTION: main
java.lang.OutOfMemoryError
    at     android.graphics.Bitmap.nativeCreate(Native Method)
    at     android.graphics.Bitmap.createBitmap(Bitmap.java:604)
    at     android.graphics.Bitmap.createBitmap(Bitmap.java:551)
    at     com.android.restaurant.DescriptionPage.getResizedBitmap(DescriptionPage.java:327)
    at         com.android.restaurant.DescriptionPage.setDetailsIntoLayout(DescriptionPage.java:172)
    at com.android.restaurant.DescriptionPage.onCreate(DescriptionPage.java:101)
    at android.app.Activity.performCreate(Activity.java:4397)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1782)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1834)
    at android.app.ActivityThread.access$500(ActivityThread.java:125)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1027)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:132)
    at android.app.ActivityThread.main(ActivityThread.java:4135)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:491)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
    at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

5

Since you have not posted your code it is hard to know whether there is a bug or probably ineffective code that can be improved.

But generally the JVM memory is limited, so loading of big image can cause OutOfMemoryError. You can try to increase the JVM memory using -Xmx option. This is the first and the simplest way.

Other way is to decrease your image (if it is possible). Or probably use format other than BMP (e.g. JPG). It guarantees good quality and requires less memory.

于 2012-04-16T06:14:56.843 回答
0

开发移动应用程序的挑战是您的内存有限。

我想到的第一件事是尝试使用 PNG(便携式网络图形)而不是位图(如果可能的话)。

除此之外,这似乎是现有问题,请检查:- http://code.google.com/p/android/issues/detail?id=8488

于 2012-04-16T06:32:27.880 回答