我從MediaStore.Images.Thumbnails.getThumbnail(請參見下文)中偶然發現(非常罕見)異常。建議類似的問題總是關閉遊標,但我沒有執行明確的查詢。來自MediaStore.Images.Thumbnails.get的CursorWindowAllocationException異常Thumbnail
我這樣稱呼它:
私有函數讀取的縮略圖。(
private Bitmap getThumbnail(long imageId) { return MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(), imageId,
MediaStore.Images.Thumbnails.MINI_KIND, null); }
從這裏稱爲:
Cursor cursor = null;
int numProcessed = 0, numFaceDetected = 0;
try {
dirtyFile.createNewFile();
String[] projection = {
MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.ORIENTATION
};
cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection,
null,
null,
MediaStore.Images.Media.DATE_ADDED + " desc");
if (cursor == null) {
return;
}
cursor.moveToFirst();
final int columnIndexId = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
final int columnIndexData = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
final int columnIndexOrientation = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.ORIENTATION);
final int columnIndexBucketName = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
while (!cursor.isAfterLast()) {
final long imageId = cursor.getLong(columnIndexId);
final String imagePath = cursor.getString(columnIndexData);
final int imageOrientation = cursor.getInt(columnIndexOrientation);
Bitmap bitmap = getThumbnail(imageId);
faceDetect(bitmap);
cursor.moveToNext();
numProcessed++;
}
這裏是個例外:
android.database.CursorWindowAllocationException: Cursor window could not be created from binder.
at android.database.CursorWindow.(CursorWindow.java:137)
at android.database.CursorWindow.(CursorWindow.java:42)
at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:685)
at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:683)
at android.database.BulkCursorDescriptor.readFromParcel(BulkCursorDescriptor.java:75)
at android.database.BulkCursorDescriptor$1.createFromParcel(BulkCursorDescriptor.java:34)
at android.database.BulkCursorDescriptor$1.createFromParcel(BulkCursorDescriptor.java:30)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:423)
at android.content.ContentResolver.query(ContentResolver.java:478)
at android.content.ContentResolver.query(ContentResolver.java:422)
at android.provider.MediaStore$InternalThumbnails.getThumbnail(MediaStore.java:680)
at android.provider.MediaStore$Images$Thumbnails.getThumbnail(MediaStore.java:1060)
你可以添加與此相關的整個代碼嗎? – dex
@dex謝謝你看看.. –