这个错误说明下标溢出,
例子:
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);
}
本文详细解释了如何避免在使用Android Cursor时遇到的下标溢出错误,通过将Cursor定位到第一条数据来修正问题,并提供了实例代码进行演示。
13万+

被折叠的 条评论
为什么被折叠?



