【发布时间】:2017-01-13 16:47:59
【问题描述】:
我在下面的代码中使用了嵌套游标。它们都不是空的,但我收到错误 内部光标上的“android.database.CursorIndexOutOfBoundsException:请求索引 0,大小为 0”。
Cursor cursor3 = null;
Cursor cursor2 = db.getAllFriendsChat();
cursor2.moveToFirst();
while (!cursor2.isAfterLast()) {
String number = cursor2.getString(cursor2.getColumnIndexOrThrow(ChatModel.COLUMN_CHAT_SENT_TO));
cursor3 = db.getName(number);
String name = cursor3.getString(cursor3.getColumnIndexOrThrow(db.KEY_NAME));
db.insertList(name, number);
cursor3.close();
cursor2.moveToNext();
}
cursor2.close();
getName() 方法:
public Cursor getName(String phone) {
SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery("select * from " + TABLE_STUDENTS + " where phone_number = " + phone, null);
if (c != null) {
c.moveToFirst(); //***I see that this statement is executed.***
}
return c;
}
我无法理解我在哪里做错了。是否有不同的方法来处理 sqlite db 中的嵌套游标。请帮忙。
谢谢!
【问题讨论】: