1
我的Android應用程序崩潰,在下面的代碼行:Android應用程序崩潰的遊標查詢(圖片/視頻光標)
Cursor cursor= getActivity().getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,columns,
selection, selectionArgs, orderBy);
崩潰日誌:
08-26 13:15:19.307 6992 6992 E AndroidRuntime: FATAL EXCEPTION: main
08-26 13:15:19.307 6992 6992 E AndroidRuntime: android.database.CursorWindowAllocationException: Cursor window could not be created from binder.
08-26 13:15:19.307 6992 6992 E AndroidRuntime: at android.database.CursorWindow.<init>(CursorWindow.java:133)
08-26 13:15:19.307 6992 6992 E AndroidRuntime: at android.database.CursorWindow.<init>(CursorWindow.java:41)
08-26 13:15:19.307 6992 6992 E AndroidRuntime: at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:681)
08-26 13:15:19.307 6992 6992 E AndroidRuntime: at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:679)
08-26 13:15:19.307 6992 6992 E AndroidRuntime: at android.database.BulkCursorDescriptor.readFromParcel(BulkCursorDescriptor.java:75)
08-26 13:15:19.307 6992 6992 E AndroidRuntime: at android.database.BulkCursorDescriptor$1.createFromParcel(BulkCursorDescriptor.java:34)
08-26 13:15:19.307 6992 6992 E AndroidRuntime: at android.database.BulkCursorDescriptor$1.createFromParcel(BulkCursorDescriptor.java:30)
08-26 13:15:19.307 6992 6992 E AndroidRuntime: at android.content.ContentProviderProxy.query(ContentProviderNative.java:369)
08-26 13:15:19.307 6992 6992 E AndroidRuntime: at android.content.ContentResolver.query(ContentResolver.java:372)
08-26 13:15:19.307 6992 6992 E AndroidRuntime: at android.content.ContentResolver.query(ContentResolver.java:315)
我怎樣才能避免呢?
我懷疑下面的代碼可以是失事原因也
if (cursor!= null)
cursor.moveToFirst();
光標總是關閉。
任何幫助提前感謝。
感謝
也許,您的應用程序溢出內存限制。從[CursorWindowAllocationException](https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/database/CursorWindowAllocationException.java):當無法分配CursorWindow時拋出此異常,**最有可能是由於內存不可用。**您可能希望縮小查詢範圍。 – ozbek
有什麼方法可以建議? – Hassan