KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
public int getRecordsCount() { String countQuery = "SELECT * FROM " + TABLE_LOGIN; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(countQuery, null); if(cursor != null && !cursor.isClosed()){ cursor.close(); } // return count return cursor.getCount(); } I am trying to get the totalnumber of records in the database, but the database is getting crashed everytime with java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT * FROM login) . Please help me with the error 03-05 22:23:14.208: E/AndroidRuntime(4988): FATAL EXCEPTION: main 03-05 22:23:14.208: E/AndroidRuntime(4988): java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT * FROM login) 03-05 22:23:14.208: E/AndroidRuntime(4988): at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:34) 03-05 22:23:14.208: E/AndroidRuntime(4988): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:64) 03-05 22:23:14.208: E/AndroidRuntime(4988): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:283) 03-05 22:23:14.208: E/AndroidRuntime(4988): at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:264) 03-05 22:23:14.208: E/AndroidRuntime(4988): at com.ecomm.android.sqlite.DatabaseHandler.getRecordsCount(DatabaseHandler.java:123) 03-05 22:23:14.208: E/AndroidRuntime(4988): at com.ecomm.android.LaunchActivity.DataBaseImplementation(LaunchActivity.java:120) 03-05 22:23:14.208: E/AndroidRuntime(4988): at com.ecomm.android.LaunchActivity.onClick(LaunchActivity.java:98) 03-05 22:23:14.208: E/AndroidRuntime(4988): at android.view.View.performClick(View.java:2408) 03-05 22:23:14.
Tags (comma-separated)
Save Edits
Cancel