CursorWindow:无法从具有 1411 行 4 列的 CursorWindow 读取第 1411 行第 3 列

CursorWindow: Failed to read row 1411, column 3 from a CursorWindow which has 1411 rows, 4 columns

我正在读取一个包含 32000 个条目的数据库并像这样更新它们:

public void updateTable(@NotNull String title) {                                                                                                                                                                          
    Pattern pattern = Pattern.compile("<span id=\"v(.+?)\" class=\"v\">.+?</span>");                                          

    SQLiteDatabase database = dbwraper.getDatabase();                                                                          

    Matcher m = pattern.matcher("");                                                                                          
    ContentValues values = new ContentValues();                                                                               
    String[] args = new String[]{""};                                                                                         
    String selection = "_Id=?";                                                                                      

    HashMap<String, Integer> map = new HashMap<>();                                                                           
    try (SQLiteCursor cursor = (SQLiteCursor) database.query(TABLE_NAME,                                        
            new String[]{"_Id", "Label", "Content", "AdjustmentInfo"}, null, null, null, null, "_Id ASC")) {

        cursor.moveToFirst();
        do {
            byte[] info = cursor.getBlob(3);
            args[0] = cursor.getString(0);
            if (info == null) {
                database.delete(TABLE_NAME, selection, args);
                continue;
            }

            String content = process(dbwraper.getDeobfuscator(), cursor.getBlob(2));
            m.reset(content);
            m.matches();

            log.e("m.group(1) = " + m.group(1));
            String[] ids = m.group(1).split("-");
            int id = Integer.parseInt(ids[0]) * 1000000 + Integer.parseInt(ids[1]) * 1000 + Integer.parseInt(ids[2]);

            map.put(args[0], id);
        } while (cursor.moveToNext());                                                                                                                   
    } catch (Exception e) {                                                                                                   
        e.printStackTrace();                                                                                                  
    }                                                                                                                         

    database.beginTransaction();                                                                                              

    for (String key : map.keySet()) {                                                                                         
        args[0] = key;                                                                                                        
        values.clear();                                                                                                       
        values.put("_Id", map.get(key));                                                                             
        database.update(TABLE_NAME, values, selection, args);                                                                
    }                                                                                                                         

    database.setTransactionSuccessful();                                                                                      
    database.endTransaction();                                                                                                 
}  

当光标读取最后一个条目时出现问题。我收到此错误:

CursorWindow: Failed to read row 1411, column 3 from a CursorWindow which has 1411 rows, 4 columns.

我好像看不出问题所在。是内存分配问题吗?还是我的数据库格式不正确?

只需更改您的循环:

    cursor.moveToFirst();
    do {
       [...]
    } while (cursor.moveToNext());

    // IMPORTANT: REMOVE THIS LINE!! cursor.moveToFirst();
    while (cursor.moveToNext() {
       [...]
    }