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

Android CursorWindow:无法从具有1411行4列的CursorWindow中读取第1411行第3列,android,sqlite,android-sqlite,android-cursor,Android,Sqlite,Android Sqlite,Android Cursor,我正在读取一个包含32000个条目的数据库,并按如下方式更新它们: public void updateTable(@NotNull String title) {

我正在读取一个包含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();                                                                                                 
}  

我似乎看不出问题所在。这是内存分配问题吗?或者我的数据库格式不正确?

只需从以下位置更改循环:

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


使用
while(cursor.moveToNext()){…
,而不是
do{…}while(…)
,当然,还要删除
cursor.moveToFirst();
ok那么
DatabaseUtils#dumpCursor
显示什么呢?在
while
循环之前调用它,不,
while(…)
do不一样{…
,首先它更自然,代码更少,如果结果集为空怎么办?确定,然后在循环体中使用
while(cursor.moveToNext()){…
只需调用
cursor.getString(0)
在循环调用
Log.d
后,使用
cursor.getPosition
的值,并将其与
cursor.getCount
进行比较,如果确定,则添加
cursor.getBlob(3)
到循环体并再次运行代码ini首先删除了AdjustmentInfo列中所有具有空值的RAW,然后按照@ModularSynth建议的数据库进行查询。execSQL(“从“+表名+”中删除,其中AdjustmentInfo为空”);是否删除了
光标。moveToFirst()
line?是的,我做了。:D:D当它必须工作时。当你检索光标时,你在索引-1处。然后用第一个
moveToNext()
你到达第一行(索引=0)。然后继续到最后一行。我希望这样做4个小时。现在,与数组一样,如果要删除某个元素,我会从最后一个元素开始,然后再开始,而不是做相反的操作。此外……为什么要逐行删除表?!一次删除所有行-或者删除所有与特定条件匹配的特定行,也就是我马上就来。
    cursor.moveToFirst();
    do {
       [...]
    } while (cursor.moveToNext());
    // IMPORTANT: REMOVE THIS LINE!! cursor.moveToFirst();
    while (cursor.moveToNext() {
       [...]
    }