Android:IllegalStateException:无法从CursorWindow读取行24929,col 0

时间:2016-07-25 16:43:15

标签: android sqlite illegalstateexception

我需要帮助解决此错误:

Fatal Exception: java.lang.IllegalStateException: Couldn't read row 24929, col 0 from CursorWindow. 
Make sure the Cursor is initialized correctly before accessing data from it

在此代码中:

SQLiteDatabase db = getReadableDatabase();
Cursor res = db.rawQuery("select id from " + pTable, null);

if (res != null) {
    if (res.getCount() != 0) {
        res.moveToFirst();
        int id;
        while (!res.isAfterLast()) {
            id = res.getInt(res.getColumnIndex("id")); // <-- Error was here
            // ...
            res.moveToNext();
        }
    }
    res.close();
}

这段代码有时可以工作,但是当我有很多行(比如25k行)时,我会得到这个例外。 这是Android限制吗?

你可以帮帮我吗? 谢谢!

1 个答案:

答案 0 :(得分:-1)

 public ArrayList<Model> Name(){
    ArrayList<Model> ModelList = new ArrayList<>();
    db = getWritableDatabase();
    Cursor c = db.rawQuery(" SELECT * FROM " + pTable,null );
    while (c.moveToNext()){
        String id = c.getString(0);
 return ModelList;
}