嘿,我正在使用游标查询数据库,但没有指向任何行,即在调试时显示 mrowId = null ,count =70(我使用内容值插入的内容在那里)但是当我写 cursor.moveToNext () 或 cursor.moveToFirst(); 它会抛出光标索引超出界限异常,而 cursor.moveToNext() 或 cursor.moveToFirst() 总是在 eclipse 中的 watch 表达式中返回......我希望你理解这个问题帮助我解决这个问题...... ..感谢您
为简单起见提前提出的建议我正在粘贴代码
public Cursor getDataBaseCursor(String tableName) {
Cursor cursor = null;
try {
if (mainDatabase.isOpen()) {
String countQuery = "SELECT * FROM " + tableName;
cursor = mainDatabase.rawQuery(countQuery, null);
// cursor = mainDatabase.query(tableName, null, null, null,
// null, null, null);
if (cursor != null) {
**boolean check =cursor.moveToNext();**
return cursor;
}
} else {
createOrOpenDatabase(databaseName);
cursor = mainDatabase.query(tableName, null, null, null, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
return cursor;
}
}
} catch (Exception e) {
e.printStackTrace();
cursor = mainDatabase.query(tableName, null, null, null, null, null, null);
if (cursor != null) {
cursor.moveToNext();
return cursor;
}
}
return null;
}
调试时布尔检查为真