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

标签 java android sql sqlite

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

相关文章:

Java (maven) 将 SSL 与 Shiro 结合使用 - Tomcat 7 的 https 端口插件无法正常工作

android - 如何在每个项目的 ListView 中实现简单的类似按钮

android - 无法访问录音机

android - addView() 之后的 "resultIndex is -1, the polygon must be invalid!"

php - MySQL更新用户代码

java - Jackson 自动映射名为 @foo 的属性?

java - 如何从 InputStream 创建 Vert.x ReadStream

mysql - 从一个表中获取数据,并将该表中的每条记录插入到另一个表中

sql - 初级SQL问题)

java - setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=true on ubuntu