游标Cursor遍历报错,数组越界解决办法

换一种遍历方式,比较保险:


cursor.moveToFirst();
while (!cursor.isAfterLast()) {
    String sname = cursor.getString(cursor.getColumnIndex("sname")); 
    cursor.moveToNext();
}
或者这样写一样:

for (cursor2.moveToFirst(); !cursor2.isAfterLast(); cursor2.moveToNext()) {

    String namee = cursor2.getString(1);

}



之前这样写,一直报错数组越界:

cursor2.moveToFirst();
if (cursor2.moveToNext()){
    String namee = cursor2.getString(1);
}

展开阅读全文

没有更多推荐了,返回首页