【问题标题】:Android: IllegalStateException: Couldn't read row 24929, col 0 from CursorWindowAndroid:IllegalStateException:无法从 CursorWindow 读取第 24929 行第 0 列
【发布时间】:2016-11-29 02:56:57
【问题描述】:

我需要有关此错误的帮助:

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 行)时,我会收到此异常。 是安卓限制吗?

你能帮我解决这个问题吗? 谢谢!

【问题讨论】:

  • 试试这个 - if (res != null) { int id; while (res.moveToNext()) { id = res.getInt(res.getColumnIndex("id")); // &lt;-- Error was here // ... } res.close(); }
  • 一张表的理论最大行数为(18446744073709551616或1.8e+19左右)
  • 您的表可能没有id 列?

标签: android sqlite illegalstateexception


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 2017-02-13
    • 2017-05-22
    • 2013-05-06
    • 2020-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    相关资源
    最近更新 更多