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。我把上面代码改为如下:android

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,睡觉了。sql

相关文章
相关标签/搜索