我遇到游标索引越界异常。
我的代码如下。
SQLiteDatabase db = this.getWritableDatabase();
String completedInList = "SELECT COUNT(*) FROM " + TABLE_BUCKET_ITEMS + " WHERE "
+ KEY_BUCKET + " = " + bucketNo + " AND " + KEY_FLAG + " = 1" ;
Cursor cursor = db.rawQuery(completedInList, null);
int completed = Integer.parseInt(cursor.getString(0));
String totalNoList = "SELECT COUNT(*) FROM " + TABLE_BUCKET_ITEMS + " WHERE "
+ KEY_BUCKET + " = " + bucketNo;
cursor.close();
Cursor cursor2 = db.rawQuery(totalNoList, null);
int total = Integer.parseInt(cursor2.getString(0));
float percentage = ((float)completed) / total;
cursor2.close();
db.close();
我希望sql查询的返回值是一个数字,这就是我将索引编码为0的原因,如下所示:cursor.getString(0)
但为什么我遇到一个超出界限的游标索引?
答案 0 :(得分:3)