Java sqlite CursorIndexOutOfBoundsException中的最后一个\u insert \u id()
有人能看到这段代码中的致命缺陷吗,或者提出一个替代方案Java sqlite CursorIndexOutOfBoundsException中的最后一个\u insert \u id(),java,android,sqlite,Java,Android,Sqlite,有人能看到这段代码中的致命缺陷吗,或者提出一个替代方案 int task_id = db.rawQuery("SELECT last_insert_rowid();", null).toInt(1); 在这一行,它抛出以下异常: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 编辑: 弄明白了,空值就是问题所在 正确的代码是: int task_id = db.r
int task_id = db.rawQuery("SELECT last_insert_rowid();", null).toInt(1);
在这一行,它抛出以下异常:
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
编辑:
弄明白了,空值就是问题所在
正确的代码是:
int task_id = db.rawQuery("SELECT last_insert_rowid();", new String[] {} ).getInt(0);
它好像要崩溃了?或者它真的崩溃了?你说的撞车是什么意思?例外?什么错误消息?我收到android.database.CursorIndexOutOfBoundsException:请求索引-1,大小为1