In my application, I download images from the Internet using the image URL. I have a lot of images. So I implemented the swap technique for this, and I displayed 15 images for each page in vertical order. In this case, I scroll up / down the page to view images, at this time my application crashed and I selected an exception from memory. please can someone help me.
Logcat:
02-07 11:23:52.256: ERROR/ACRA(7236): El Gifto fatal error : bitmap size exceeds VM budget(Heap Size=7943KB, Allocated=3485KB, Bitmap Size=12546KB) 02-07 11:23:52.256: ERROR/ACRA(7236): java.lang.OutOfMemoryError: bitmap size exceeds VM budget(Heap Size=7943KB, Allocated=3485KB, Bitmap Size=12546KB) 02-07 11:23:52.256: ERROR/ACRA(7236): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 02-07 11:23:52.256: ERROR/ACRA(7236): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:690) 02-07 11:23:52.256: ERROR/ACRA(7236): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:490) 02-07 11:23:52.256: ERROR/ACRA(7236): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697) 02-07 11:23:52.256: ERROR/ACRA(7236): at android.graphics.drawable.Drawable.createFromStream(Drawable.java:657) 02-07 11:23:52.256: ERROR/ACRA(7236): at com.ibkr.elgifto.GiftCategories$itemlistadapter$3.getDrawableFromUrl(GiftCategories.java:837) 02-07 11:23:52.256: ERROR/ACRA(7236): at com.ibkr.elgifto.GiftCategories$itemlistadapter$3.run(GiftCategories.java:724)
Here is my code:
public void DownLoadImageInAThreadHandler(final CategoryData Item, final ViewHolder holder) { final Handler handler = new Handler() { @Override public void handleMessage(Message message) { holder.imgitem.setImageDrawable((Drawable) message.obj); holder.imgitem.setVisibility(View.VISIBLE); holder.progress.setVisibility(View.GONE); } }; //Thread for getting the attributes values Thread t = new Thread() { public void run() { try { drawable = getDrawableFromUrl(Item.ImageUrl); if(drawable != null) { //Send the message to the handler Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } else { int idNoImage = R.drawable.giftsuggestionsnoimage; Drawable dwgNoImg = GiftCategories.this.getResources().getDrawable(idNoImage); //Send the message to the handler Message message = handler.obtainMessage(1, dwgNoImg); handler.sendMessage(message); } } catch(Exception exp) { System.out.println("Exception in DownLoadImageInAThread : " + exp.getMessage()); } } private Drawable getDrawableFromUrl(String imageUrl) throws IOException { Drawable image = null; try { InputStream in = (java.io.InputStream) new java.net.URL(imageUrl).getContent(); if (in != null) { image = Drawable.createFromStream(in, "image"); in.close(); } } catch (Exception ex) { ex.printStackTrace(); } return image; } }; t.start(); }
source share