android sqlite android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5
Cursor c = db.query("user",null,null,null,null,null,null);//查询并获得游标
if(c.moveToFirst()){//判断游标是否为空
for(int i=0;i<c.getCount();i++){
c.move(i);//移动到指定记录
String username = c.getString(c.getColumnIndex("username");
String password = c.getString(c.getColumnIndex("password"));
}
}
在通过以上代码读取sqlite user表中多条数据时,就会发生错误:android sqlite android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5。我把上面代码改成以下:
Cursor c = db.query("user",null,null,null,null,null,null);//查询并获得游标
for(int i=0;i<c.getCount() && c!=null ;i++){
if(c.moveToFirst()){//判断游标是否为空
c.move(i);//移动到指定记录
String username = c.getString(c.getColumnIndex("username");
String password = c.getString(c.getColumnIndex("password"));
}
}
OK,睡觉了。
浙公网安备 33010602011771号