gpt4 book ai didi

创建位图时出现 java.lang.outofmemoryerror

转载 作者:行者123 更新时间:2023-12-01 07:36:53 26 4
gpt4 key购买 nike

我收到大图像(png,>30Mb)并为其创建位图。并得到java.lang.OutOfMemoryError。我 try catch 这样的异常:

try {
Bitmap bmp = BitmapFactory.decodeStream(someStream);
} catch (OutOfMemoryError e) {
;
}

使用 2.2 SDK 可以很好地工作。但 2.3 应用程序因未捕获的异常而失败。我不明白,为什么?

谢谢!

最佳答案

你并不是真的要捕获错误:

来自Javadoc :

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.

如果您遇到错误,尤其是 OutOfMemoryError,那么基本上已经来不及采取任何措施了。

关于创建位图时出现 java.lang.outofmemoryerror,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10831539/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com