gpt4 book ai didi

java - 内存不足错误: Failed to allocate a 82956 byte allocation with 30836 free bytes and 30KB until OOM?

转载 作者:太空宇宙 更新时间:2023-11-04 12:30:52 25 4
gpt4 key购买 nike

在我的应用程序中,我有一个存储图像的数据库,但是当我尝试在 BitMap 中检索图像时,logcat 显示 OutOfMemoryError 。当我从数据库中仅检索一张图像时,不会出现此错误(当我不使用 do while 循环时,我的代码运行良好)。请帮助我是 android 新手。

此类尝试从数据库检索图像:

class Abc {

ArrayList < ForBitMap > pic;

Abc() {

pic = new Abc < > ();

DataBaseClass objOfDataBaseClass = new DataBaseClass(context);
mCursor = objOfDataBaseClass.showData();

if (mCursor.moveToNext()) {

do {

byte[] mg = null;

mg = mCursor.getBlob(mCursor.getColumnIndex("image"));
Bitmap bitmap = BitmapFactory.decodeByteArray(mg, 0, mg.length);

pic.add(new ForBitMap(bitmap));

} while (mCursor.moveToFirst());

}
}

该类用于将值存储在ArrayList(ArrayList pic;)

class ForBitMap{
Bitmap btmp;

ForBitMap(Bitmap btmp){
this.btmp=btmp;
}

}

日志状态是:

java.lang.OutOfMemoryError: Failed to allocate a 82956 byte allocation with 30836 free bytes and 30KB until OOM

最佳答案

您可能不应该将位图存储在数据库中。只需将它们存储在文件存储中并将文件路径保留在数据库中即可。

关于java - 内存不足错误: Failed to allocate a 82956 byte allocation with 30836 free bytes and 30KB until OOM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37856132/

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