0
点赞
收藏
分享

微信扫一扫

android.database.CursorIndexOutOfBoundsExcept: Index -1 requested, with a size of 1

九点韶留学 2023-02-07 阅读 64



这个错误说明下标溢出,


例子:

Cursor cursor = getContentResolver().query(uri, new String[]{"contact_id"}, null, null, "contact_id desc limit 1"); //这有

一行数据

f(cursor !=null && cursor.getCount()>0){
int contact_id = cursor.getInt(0); //此时选择还在-1行,这里出错误
}

        改成:

f(cursor !=null && cursor.moveToFirst()){//直接指向第一行
int contact_id = cursor.getInt(0);
}

   





举报

相关推荐

0 条评论