staledataexception

How to close a cursor used in a for loop

时光总嘲笑我的痴心妄想 提交于 2019-12-24 16:05:47
问题 Background I have a cursor used as follows: for (int n=0; n<num_songs; n++) { boolean isChecked = checked_positions.get(n); if (isChecked) { Cursor cursor = (Cursor) getListView().getItemAtPosition(n); String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)); String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)); cursor.close(); //save artist and title strings to file... } } This gives a StaleDataException on the second time round

Can someone explain to me this `StaleDataException`

自闭症网瘾萝莉.ら 提交于 2019-12-23 10:57:39
问题 Can someone explain to me this StaleDataException 07-11 19:58:23.298 E/AndroidRuntime( 1044): Uncaught handler: thread main exiting due to uncaught exception 07-11 19:58:23.368 E/AndroidRuntime( 1044): android.database.StaleDataException: Access closed cursor 07-11 19:58:23.368 E/AndroidRuntime( 1044): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:217) 07-11 19:58:23.368 E/AndroidRuntime( 1044): at android.database.AbstractWindowedCursor.getInt

Closing Cursor causes StaleDataException on backgrounding fragment with CursorAdapter

◇◆丶佛笑我妖孽 提交于 2019-12-13 02:48:30
问题 This is a follow up to my question here: How to close a cursor used in a for loop The responses solved the "Cursor finalized without prior close" warning but it has caused a StaleDataException in a very particular situation. If the list has been scrolled, this cursor closed... Cursor cursor = null; cursor = (Cursor) getListView().getItemAtPosition(n); //do something if(cursor != null) { cursor.close(); } and the fragment backgrounded I get the following error: 09-15 21:16:58.240: E/test(21621

StaleElementReference Exception

非 Y 不嫁゛ 提交于 2019-12-12 02:22:51
问题 I am struggling with the StaleElementReferenceException problem. I have seen quite a number of discussions on the topic but I haven't been able to find a solution to the issue that I am facing. The test is to get all the links on the footer of the web page and then verify whether the link is active or not by clicking on it and verifying the title of the page. First of all, I find & store all the links in an array list. I compare the link name with the values retrieved from the database. Then

Merging cursors during onLoadFinished() causes StaleDataException after rotation

白昼怎懂夜的黑 提交于 2019-12-07 13:30:49
问题 I'm loading some results from a database using a loaderManager. Unfortunately, the following code produces a StaleDataException after rotating the device: @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { // If we've returned results, then pass them and the webSearches cursor along to be displayed if(cursor.moveToFirst()) { // Get a cursor containing additional web searches and merge it at the end of the results cursor MatrixCursor searchesCursor =

Merging cursors during onLoadFinished() causes StaleDataException after rotation

谁都会走 提交于 2019-12-05 22:52:38
I'm loading some results from a database using a loaderManager. Unfortunately, the following code produces a StaleDataException after rotating the device: @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { // If we've returned results, then pass them and the webSearches cursor along to be displayed if(cursor.moveToFirst()) { // Get a cursor containing additional web searches and merge it at the end of the results cursor MatrixCursor searchesCursor = getWebSearchesCursor(searchTerm, false); Cursor[] cursors = { cursor, searchesCursor }; // TODO: Figure out why merging