我想從我的表中的記錄數,但我不能,因爲我得到這個錯誤:如何從SQLLiteDatabase中獲取表中所有記錄的數量?
06-19 19:11:12.599: E/AndroidRuntime(1811): java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT * FROM zapisy)
我的功能:
// Getting contacts Count
public int getContactsCount() {
String countQuery = "SELECT * FROM " + TABLE_ZAPISY;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();
// return count
return cursor.getCount();
}
我發現這個功能在這個網站:http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/
怎麼了?爲什麼它不起作用?