-1

我是android新手,我已经使用带有图像的sqlite创建了一个数据库。当我查看我插入到数据库中的所有数据时,只有热度(字符串行)显示所有记录,但图像只显示第一行。任何人都可以请帮助我,我现在很绝望。

public String getHot() {
             // TODO Auto-generated method stub

    String[] columns = new String[] { KEY_HOTNESS };
            Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,null,null);

    String hotness = "";
    int iRow = c.getColumnIndex(KEY_HOTNESS);
    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        hotness = hotness + c.getString(iRow) + "\n";
    }
    return hotness;
}

public byte[] getImage1(int id) {
    // TODO Auto-generated method stub

    String[] columns = new String[] { KEY_ROWID, KEY_NAME, KEY_HOTNESS,
    KEY_IMAGE1, KEY_IMAGE2, KEY_IMAGE3, KEY_IMAGE4,KEY_IMAGE5 };

    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
            null, null);
    if (c == null) {
        return null;
    }
    byte[] iMage1 = null;
    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        iMage1 = c.getBlob(c.getColumnIndexOrThrow(KEY_IMAGE1));
    }
    return iMage1;
}
4

1 回答 1

1

java.lang.OutOfMemoryError: bitmap这是您的解决方案:但如果您的图像尺寸很大,它也会给您。

public ArrayList<Bitmap> getImage1(int id) { 
        // TODO Auto-generated method stub
        ArrayList<Bitmap> a = new ArrayList<Bitmap>();
        Bitmap bmp;

        String[] columns = new String[] { KEY_ROWID, KEY_NAME, KEY_HOTNESS,
                KEY_IMAGE1, KEY_IMAGE2, KEY_IMAGE3, KEY_IMAGE4, KEY_IMAGE5 };

        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
                null, null);
        if (c != null) {
            do {
                iMage1 = c.getBlob(c.getColumnIndexOrThrow(KEY_IMAGE1));
                bmp = BitmapFactory.decodeByteArray(iMage1, 0,
                        iMage1.length);
                a.add(bmp);
                iMage1 = c.getBlob(c.getColumnIndexOrThrow(KEY_IMAGE2));
                bmp = BitmapFactory.decodeByteArray(iMage1, 0,
                        iMage1.length);
                a.add(bmp);
                iMage1 = c.getBlob(c.getColumnIndexOrThrow(KEY_IMAGE3));
                bmp = BitmapFactory.decodeByteArray(iMage1, 0,
                        iMage1.length);
                a.add(bmp);
                iMage1 = c.getBlob(c.getColumnIndexOrThrow(KEY_IMAGE4));
                bmp = BitmapFactory.decodeByteArray(iMage1, 0,
                        iMage1.length);
                a.add(bmp);
                iMage1 = c.getBlob(c.getColumnIndexOrThrow(KEY_IMAGE5));
                bmp = BitmapFactory.decodeByteArray(iMage1, 0,
                        iMage1.length);
                a.add(bmp);

            } while (c.moveToNext());
        }

        return a;
    }
于 2013-04-03T09:53:24.800 回答