CursorWindowAllocationException:光标窗口分配2048 kb失败

时间:2019-11-05 06:59:32

标签: android sqlite android-sqlite

我知道这是个老问题。但是,即使我尝试了所有可能的解决方案,该崩溃仍在Play商店中发生。这主要是在后台模式下发生的。这是我的代码:-

 public String readKeyData(String id) {
        String Query = "SELECT " + KEY_FLOAT + " FROM " + TABLE_DATA + " where " + KEY_ID + " =\"" + id + "\" ";
        SQLiteDatabase db = getReadableDatabase();
        Cursor cursor = db.rawQuery(Query, null);
        String key;
        if (cursor != null) {
            if (cursor.moveToNext()) {
                //db.close();
                key= String.valueOf(cursor.getFloat(0));
                cursor.close();
                return key;
            } else {
                //db.close();
                cursor.close();
                return null;
            }
        } else {
            //db.close();
            return null;
        }

    }

另外,我有下面的代码

 public Cursor readAuthatizedData() {
        String countQuery = "SELECT  * FROM " + TABLE_DATA + " where " + T_ID + " != " + -1 + " AND " + DELETED_PERMANAT + " = " + 0 +" AND "+ AUTHENTICATION+" = "+ 0;
        SQLiteDatabase db = getReadableDatabase();
        Cursor cursor = db.rawQuery(countQuery, null);
        cursor.moveToPosition(-1);
        return cursor;
    }

在这种情况下,游标对象将在返回的函数中关闭。

上述代码是否有误? 有没有更好的方法来解决此崩溃?

0 个答案:

没有答案