我的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();
光标始终关闭。
提前获得任何帮助。
由于
答案 0 :(得分:0)
试试这个技巧
Cursor cursor= getApplicationContext().getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,columns,
selection, selectionArgs, orderBy);
if (cursor != null) {
if (cursor.moveToFirst()) {
///// Put your idea here
}
cursor.close();
}