我正在运行以下查询:
String q = "select " + MySQLiteHelper.COLUMN_ID + ", "
+ MySQLiteHelper.COLUMN_TASK + ", "
+ MySQLiteHelper.COLUMN_PARENT + ", count(*) from "
+ MySQLiteHelper.TABLE_TASKS + " where "
+ MySQLiteHelper.COLUMN_ID + " = " + insertId + " group by "
+ MySQLiteHelper.COLUMN_ID + ", " + MySQLiteHelper.COLUMN_TASK
+ ", " + MySQLiteHelper.COLUMN_PARENT;
Cursor cursor = database.rawQuery(q, null);
当我像这样读取检索到的数据时:
task.setId(cursor.getLong(0));
task.setTask(cursor.getString(1));
task.setParent(cursor.getLong(2));
task.setChildren(cursor.getInt(3));
我收到以下错误:
03-15 22:15:06.078: E/AndroidRuntime(31426):
java.lang.IllegalStateException:
Couldn't read row 0, col 3 from CursorWindow.
Make sure the Cursor is initialized correctly before accessing data from it.
如果我删除线
task.setChildren(cursor.getInt(3));
它工作正常。
谁能告诉我这里出了什么问题以及如何解决?