4
這是片段活動它強制關閉時,我按Home鍵,錯誤是試圖訪問遊標後已被關閉。錯誤在哪裏?我也嘗試getContentResolver()。query()而不是managedQuery()相同的錯誤。android.database.StaleDataException:試圖訪問遊標後已關閉
和我的MainActivity是SherlockFragmentActivity標籤和查看傳呼機
private Cursor getInternalAudioCursor(String selection,
String[] selectionArgs) {
return getActivity().managedQuery(
MediaStore.Audio.Media.INTERNAL_CONTENT_URI,
INTERNAL_COLUMNS,
selection,
selectionArgs,
MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
}
private Cursor getExternalAudioCursor(String selection,
String[] selectionArgs) {
return getActivity().managedQuery(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
EXTERNAL_COLUMNS,
selection,
selectionArgs,
MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
}
Cursor createCursor(String filter) {
ArrayList<String> args = new ArrayList<String>();
String selection;
if (mShowAll) {
selection = "(_DATA LIKE ?)";
args.add("%");
} else {
selection = "(";
for (String extension : CheapSoundFile.getSupportedExtensions()) {
args.add("%." + extension);
if (selection.length() > 1) {
selection += " OR ";
}
selection += "(_DATA LIKE ?)";
selection = selection + "AND (IS_MUSIC=1)";
}
selection += ")";
selection = "(" + selection + ") AND (_DATA NOT LIKE ?)";
args.add("%espeak-data/scratch%");
}
if (filter != null && filter.length() > 0) {
filter = "%" + filter + "%";
selection =
"(" + selection + " AND " +
"((TITLE LIKE ?) OR (ARTIST LIKE ?) OR (ALBUM LIKE ?)))";
args.add(filter);
args.add(filter);
args.add(filter);
}
String[] argsArray = args.toArray(new String[args.size()]);
getExternalAudioCursor(selection, argsArray);
getInternalAudioCursor(selection, argsArray);
Cursor c = new MergeCursor(new Cursor[] {
getExternalAudioCursor(selection, argsArray),
getInternalAudioCursor(selection, argsArray)});
getActivity().startManagingCursor(c);
return c;
}
Eroor日誌:
01-13 15:02:16.049: E/AndroidRuntime(12435): java.lang.RuntimeException: Unable to resume activity {com.my.ringtone/com.my.ringtone.MainActivity}: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
01-13 15:02:16.049: E/AndroidRuntime(12435): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2946)
01-13 15:02:16.049: E/AndroidRuntime(12435): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2975)
01-13 15:02:16.049: E/AndroidRuntime(12435): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
01-13 15:02:16.049: E/AndroidRuntime(12435): at android.os.Handler.dispatchMessage(Handler.java:102)
01-13 15:02:16.049: E/AndroidRuntime(12435): at android.os.Looper.loop(Looper.java:157)
01-13 15:02:16.049: E/AndroidRuntime(12435): at android.app.ActivityThread.main(ActivityThread.java:5356)
01-13 15:02:16.049: E/AndroidRuntime(12435): at java.lang.reflect.Method.invokeNative(Native Method)
01-13 15:02:16.049: E/AndroidRuntime(12435): at java.lang.reflect.Method.invoke(Method.java:515)
01-13 15:02:16.049: E/AndroidRuntime(12435): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
01-13 15:02:16.049: E/AndroidRuntime(12435): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
01-13 15:02:16.049: E/AndroidRuntime(12435): at dalvik.system.NativeStart.main(Native Method)
01-13 15:02:16.049: E/AndroidRuntime(12435): Caused by: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
01-13 15:02:16.049: E/AndroidRuntime(12435): at android.database.BulkCursorToCursorAdaptor.throwIfCursorIsClosed(BulkCursorToCursorAdaptor.java:64)
張貼您的logcat ... –
關閉您的光標使用後。 –
是的......但在哪裏? – Higginslpert