I sometimes see this error in my logcat
output,
Cursor: invalid statement in fillWindow().
It sometimes happens when I press the back key and then it goes to the default Android listview
before going to my custom listview
.
What does it mean? How do I solve it? Because it does not point to any line of code where the problem is coming from.
Cursors are what contain the result set of a query made against a database in Android. The Cursor class has an API that allows an app to read (in a type-safe manner) the columns that were returned from the query as well as iterate over the rows of the result set.
This interface provides random read-write access to the result set returned by a database query. Cursor implementations are not required to be synchronized so code using a Cursor from multiple threads should perform its own synchronization when using the Cursor.
When dealing with ListActivities, this issue has to do with the Cursor objects, CursorAdapter objects, and Database objects not being closed properly when the Activity stops, and not being set properly when the Activity starts or resumes.
I had to make sure that I closed my SimpleListAdapter, my Cursors, and then my Database objects in that respective order, in the onStop method of the Activity that is called when the TabActivity resumes.
I had already been closing the Cursor and Database objects, but had not been closing my SimpleListAdapter Cursor.
/** * onStop method * * Perform actions when the Activity is hidden from view * * @return void * */ @Override protected void onStop() { try { super.onStop(); if (this.mySimpleListAdapterObj !=null){ this.mySimpleListAdapterObj.getCursor().close(); this.mySimpleListAdapterObj= null; } if (this.mActivityListCursorObj != null) { this.mActivityListCursorObj.close(); } if (this.myDatabaseClassObj != null) { this.myDatabaseClassObj.close(); } } catch (Exception error) { /** Error Handler Code **/ }// end try/catch (Exception error) }// end onStop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With