本文介绍了java.lang.OutOfMemoryError即使在try-catch块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序崩溃,显示此logcat中:
java.lang.OutOfMemoryError: (Heap Size=39047KB, Allocated=19932KB)
at android.graphics.BitmapFactory.nativeDecodeFile(Native Method)
at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:373)
at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:443)
at com.mApp.mobileapp.mActivity.onActivityResult(mActivity.java:196)
at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:153)
at android.app.Activity.dispatchActivityResult(Activity.java:4752)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3449)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3503)
at android.app.ActivityThread.access$1100(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1320)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:5109)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:991)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:758)
at dalvik.system.NativeStart.main(Native Method)
虽然运行此code:
String selectedImagePath = data.getStringExtra("imageByteCode");
try {
File imageFile = new File(selectedImagePath);
Bitmap bitmap = BitmapFactory.decodeFile(imageFile
.getAbsolutePath());//line 196
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
base64code = selectedImagePath;
mImage.setImageBitmap(bitmap);
} catch (Exception e) {
}
因为我是赶上了,我从来没有预料到崩溃的应用程序。 selectedImagePath
是SD卡,其中不超过所选图像的路径 3m.b ,但堆大小= 39047KB,分配= 19932KB ?
Since i was catching it, i never expected it to crash the app. selectedImagePath
is the path of the selected image on the SD card, which never exceeds 3m.b but Heap Size=39047KB, Allocated=19932KB ??
感谢您
推荐答案
您没抓住。 的OutOfMemoryError
是错误衍生
,不是从例外
。这是一个错误
因为通常一个应用程序是不是应该抓住它,就几乎为零您的应用程序可以做恢复。
You did not catch it. OutOfMemoryError
is derived from Error
, not from Exception
. It is an Error
because normally an application is not supposed to catch it, there is close to nothing your application can do to recover.
这篇关于java.lang.OutOfMemoryError即使在try-catch块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!