I get this error after switching to this activity, starting a new one, returning. This does not happen when I load activity first. functionally everything works ... but I still get this error.
ERROR / Cursor (1059): Termination A cursor that has not been deactivated or closed. database = /data/data/com.roger.testapp/databases/data, table = null, query = SELECT MAX (_id) FROM record
03-02 16: 47: 21.835: ERROR / Cursor (+1059): android.database.sqlite.DatabaseObjectNotClosedException: The application did not close the cursor or database object that was opened here
In onCreate:
mDbHelper = new CommonDbAdapter(this); mDbHelper.open(); fillData();
fillData () calls fetchNote in my dbhelper, the cursor is used for a couple of things, if rowId == 0, this means that I did not select an element to enter this action, and I want to get the last row in this table. if rowId = something else, then I take this line. I think the problem is here somewhere, I'm just not sure.
public Cursor fetchNote(long rowId, String table, String columns) throws SQLException { if (rowId == 0) { String query = "SELECT MAX(_id) FROM record"; Cursor cursor = mDb.rawQuery(query, null); rowId = 0; if (cursor.moveToFirst()) { rowId = cursor.getInt(0); } } Cursor mCursor = mDb.query(true, table, new String[] {KEY_ROWID, columns}, KEY_ROWID + "=" + rowId, null, null, null, null, null); if (mCursor != null) { mCursor.moveToFirst(); } return mCursor; }
In onDestroy:
super.onDestroy(); if (mDbHelper != null) { mDbHelper.close(); }
In addition, I run CommandCursor