在我的应用程序中,我有一个存储图像的数据库,但是当我尝试在 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/