我有
public boolean isEmpty()
{
if (database == null) {
database = dbHelper.getReadableDatabase(); // or similar method that
}
Cursor cursor = database.rawQuery("SELECT COUNT(*) FROM " + DatabaseHelper.TABLE_ENCOURAGEMENTS, null);
if (cursor != null) {
return false;
} else {
return true;
}
}
但是当我在空数据库上运行它时,它会崩溃。
有什么建议么?
错误是:
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:2144)
Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested,
with a size of 0