I have an image gallery application and am trying to get an image from external storage. My application can run on an Android emulator, but on a real device (HTC OneX) I have some kind of exception.
My magazine is here.
07-25 17:17:49.027: E/dalvikvm-heap(3008): Out of memory on a 480016-byte allocation. 07-25 17:17:49.052: E/dalvikvm(3008): Out of memory: Heap Size=65571KB, Allocated=63717KB, Limit=65536KB 07-25 17:17:49.052: E/dalvikvm(3008): Extra info: Footprint=65315KB, Allowed Footprint=65571KB, Trimmed=0KB 07-25 17:17:49.052: E/MediaStore(3008): failed to allocate memory for thumbnail content://media/external/images/thumbnails/300; java.lang.OutOfMemoryError: (Heap Size=65571KB, Allocated=63717KB) 07-25 17:17:49.142: E/dalvikvm-heap(3008): Out of memory on a 480016-byte allocation. 07-25 17:17:49.152: E/dalvikvm(3008): Out of memory: Heap Size=65571KB, Allocated=63718KB, Limit=65536KB 07-25 17:17:49.152: E/dalvikvm(3008): Extra info: Footprint=65315KB, Allowed Footprint=65571KB, Trimmed=0KB 07-25 17:17:49.152: E/MediaStore(3008): failed to allocate memory for thumbnail content://media/external/images/thumbnails/300; java.lang.OutOfMemoryError: (Heap Size=65571KB, Allocated=63718KB) 07-25 17:17:49.302: E/dalvikvm-heap(3008): Out of memory on a 480016-byte allocation. 07-25 17:17:49.317: E/dalvikvm(3008): Out of memory: Heap Size=65571KB, Allocated=63749KB, Limit=65536KB 07-25 17:17:49.317: E/dalvikvm(3008): Extra info: Footprint=65315KB, Allowed Footprint=65571KB, Trimmed=0KB 07-25 17:17:49.327: E/AndroidRuntime(3008): FATAL EXCEPTION: AsyncTask
And my code is here.
final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID }; Cursor image_cursor; image_cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, null, null); int image_column_index = image_cursor .getColumnIndex(MediaStore.Images.Media._ID); count = image_cursor.getCount(); thumbnails = new Bitmap[count]; arrPath = new String[count]; try { for (int i = 0; i < count; i++) { image_cursor.moveToPosition(i); int id = image_cursor.getInt(image_column_index); int dataColumnIndex = image_cursor .getColumnIndex(MediaStore.Images.Media.DATA); thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail( getApplicationContext().getContentResolver(), id, MediaStore.Images.Thumbnails.MINI_KIND, null); arrPath[i] = image_cursor.getString(dataColumnIndex); } } catch (Exception e) { e.printStackTrace(); }
Sorry for my language. Thanks.
source share