Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java sqlite CursorIndexOutOfBoundsException中的最后一个\u insert \u id()_Java_Android_Sqlite - Fatal编程技术网

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