java.lang.OutOfMemoryError: bitmap size exceeds VM budget on line Drawable.createFromStream(((java.i


First I'm creating an Arraylist of images and image information by parsing json response

`JSONArray jsonArray = jsonObj.getJSONArray("result"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObjInner = jsonArray.getJSONObject(i); ImageInfo imageInfo = new ImageInfo(); imageInfo.setImageUrl("http://www.dvimaytech.com/markphoto/" + jsonObjInner.getString("image")); new GetDrawableFromUrl(imageInfo).execute(); imageInfo.setEmail(jsonObjInner.getString("emailid")); imageInfo.setImage_id(jsonObjInner.getString("image_id")); imageInfo.setImage_name(jsonObjInner.getString("image_name")); imageInfo.setAmount(jsonObjInner.getString("amount")); imageInfo.setImage_description(jsonObjInner.getString("image_description")); imageInfo.setDate_created(jsonObjInner.getString("date_created")); }`

Then I get images from server another in Async task using the code

public class GetDrawableFromUrl extends AsyncTask<Void, Void, Drawable> { public ImageInfo imageInfoObj; GetDrawableFromUrl(ImageInfo imageInfo) { imageInfoObj = imageInfo; } @Override protected Drawable doInBackground(Void... params) { try { return Drawable.createFromStream(((java.io.InputStream) new java.net.URL(imageInfoObj.getImageUrl()).getContent()), "src_name"); } catch (Exception e) { e.printStackTrace(); } return null; } protected void onPostExecute(Drawable drawable) { if (drawable != null) { imageInfoObj.setImage(drawable); listImageInfo.add(imageInfoObj); showImagesInList(); } } }

My adapter class code

public class MyImageListAdapter extends BaseAdapter { private LayoutInflater inflater = null; public MyImageListAdapter() { inflater = (LayoutInflater) HomeActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public int getCount() { return listImageInfo.size(); } public Object getItem(int position) { return listImageInfo.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { View vi = convertView; if (convertView == null) { vi = inflater.inflate(R.layout.list_row, null); } TextView tvName = (TextView) vi.findViewById(R.id.tv_name); TextView tvTime = (TextView) vi.findViewById(R.id.tv_time); ImageView image = (ImageView) vi.findViewById(R.id.iv_image); final Button btnDelete = (Button) vi.findViewById(R.id.btn_delete); image.setImageDrawable(listImageInfo.get(position).getImage()); tvName.setText("Name: " + listImageInfo.get(position).getImage_name()); tvTime.setText("Date: " + listImageInfo.get(position).getDate_created()); btnDelete.setOnClickListener(new OnClickListener() { public void onClick(View v) { final int position = listView.getPositionForView((View) v.getParent()); positionOgBtnToDelete = position; Log.v("delete btn clicked", "delete btn no: " + position); Toast.makeText(HomeActivity.this, "Btn delete position: " + position, Toast.LENGTH_LONG).show(); showAlertToConfirmDelete(); } }); return vi; } }

Now my list only contains 5-6 images. But I'm getting error OutOfMemory error on line

return Drawable.createFromStream(((java.io.InputStream) new java.net.URL(imageInfoObj.getImageUrl()).getContent()), "src_name");

My log - cat is

E/dalvikvm-heap(10927): 7680000-byte external allocation too large for this process. : D/dalvikvm(10927): GC_FOR_MALLOC freed 0K, 55% free 3286K/7303K, external 54717K/56765K, paused 32ms : E/GraphicsJNI(10927): VM won't let us allocate 7680000 bytes : D/skia(10927): libjpeg error 105 < Ss=%d, Se=%d, Ah=%d, Al=%d> from allocPixelRef [1600 1200] D/skia(10927): --- decoder->decode returned false W/dalvikvm(10927): threadid=9: thread exiting with uncaught exception (group=0x40018578) E/AndroidRuntime(10927): FATAL EXCEPTION: AsyncTask #1 E/AndroidRuntime(10927): java.lang.RuntimeException: An error occured while executing doInBackground() E/AndroidRuntime(10927): at android.os.AsyncTask$3.done(AsyncTask.java:200) E/AndroidRuntime(10927): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274) E/AndroidRuntime(10927): at java.util.concurrent.FutureTask.setException(FutureTask.java:125) E/AndroidRuntime(10927): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308) E/AndroidRuntime(10927): at java.util.concurrent.FutureTask.run(FutureTask.java:138) E/AndroidRuntime(10927): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) E/AndroidRuntime(10927): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) E/AndroidRuntime(10927): at java.lang.Thread.run(Thread.java:1019) E/AndroidRuntime(10927): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget E/AndroidRuntime(10927): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) E/AndroidRuntime(10927): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:573) E/AndroidRuntime(10927): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:439) E/AndroidRuntime(10927): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697) E/AndroidRuntime(10927): at android.graphics.drawable.Drawable.createFromStream(Drawable.java:657) E/AndroidRuntime(10927): at com.markphoto_activities.DisplayImagesActivity$GetDrawableFromUrl.doInBackground(DisplayImagesActivity.java:257) E/AndroidRuntime(10927): at com.markphoto_activities.DisplayImagesActivity$GetDrawableFromUrl.doInBackground(DisplayImagesActivity.java:1) E/AndroidRuntime(10927): at android.os.AsyncTask$2.call(AsyncTask.java:185) E/AndroidRuntime(10927): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) E/AndroidRuntime(10927): ... 4 more D/dalvikvm(10927): GC_EXTERNAL_ALLOC freed 122K, 55% free 3329K/7303K, external 55034K/56765K, paused 49ms E/dalvikvm-heap(10927): 4194304-byte external allocation too large for this process. D/dalvikvm(10927): GC_FOR_MALLOC freed <1K, 55% free 3329K/7303K, external 55034K/56765K, paused 32ms E/GraphicsJNI(10927): VM won't let us allocate 4194304 bytes

Instead of this, I'm showing the same list on another activity, where I'm doing the same process.

Also there are other two activities where 1. I capture image using camera intent and upload to server(calling api and using Http Multipart Entity), and 2. I upload images from gallery.

This is not the only place I'm getting this error, in fact a lot at other places. But 90% error comes on this line.

I want to know, whether the problem is coming because of a single large size image of all images together taking more memory. And how to remove it?


Use a Image loader You can find an example <a href="https://github.com/novoda/ImageLoader" rel="nofollow">here</a>


  • Password validation - adding additional requirments
  • java.lang.OutOfMemoryError: bitmap size exceeds VM budget on line Drawable.createFromStream(((java.i
  • error in gridview with image url
  • Firebase Android ListView not being displayed
  • Best practice of showing gif in Android
  • Why are some constants public and other private in an Android library code
  • How to detect a moment when ListView item becomes ActiveView (going off-screen)
  • How to add view to gridview programmatically, android?
  • How to handle Button click and Listview click on a single row?
  • Why doesn't DefaultStyleKey change the default style for my subclasses?
  • CoreNLP Stanford Dependency Format
  • Divide two String into substrings and pair them
  • System IO Exception : the process cannot access the file because it is being used by another process
  • set onClickListener in getview() with ViewHolder class
  • bidirectional named pipe question
  • Java Exception: unknown protocol: udp
  • How to store edit text data from an Android dialog?
  • How to save state of CheckBox while scrolling in ListView?
  • android save bitmap without compression
  • Fragment tabhost is not working in Fragment
  • Binary XML file line #26: Duplicate id, tag null, or parent id with another fragment
  • List view crashes when scrolling “The application may be doing too much work on its main thread.”
  • PXAction seemingly does nothing
  • Variant from android-autofittextview library : scaling makes strange behaviour
  • How Can I Prevent Activation For Some ListView Items When The Selection Mode Is MultiChoiceModal?
  • SearchView WITHOUT ACTIONBAR [duplicate]
  • BizTalk Party not being resolved for incoming HL7v2 message
  • Unicorn and Rails eat up 2x MySQL connections
  • How to Make a Spinner (In a Fragment) That Changes the App's Language?
  • Wrong row deleted from custom listview with spinner
  • Syntax error on tokens, AnnotationName expected instead - error on query
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • how to do an event when i swipe from fragment to the other
  • Opengl-es onTouchEvents problem or a draw problem? [closed]
  • output of program is not same as passed argument
  • Javascript + PHP Encryption with pidCrypt
  • Getting Messege Twice Using IMvxMessenger
  • How to stop GridView from loading again when I press back button?
  • How can i traverse a binary tree from right to left in java?
  • How can I use threading to 'tick' a timer to be accessed by other threads?