How to close a cursor used in a for loop
问题 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