1

I am trying to retrieve a list of images and text from a web service. I have first coded to get the images to a list using Simple Adapter. The images are getting displayed the app is showing an error and in the Logcat the following errors occur...

04-26 10:55:39.483: ERROR/dalvikvm-heap(1047): 8850-byte external allocation too large for this process.
04-26 10:55:39.493: ERROR/(1047): VM won't let us allocate 8850 bytes
04-26 10:55:39.563: ERROR/AndroidRuntime(1047): Uncaught handler: thread Thread-96 exiting due to uncaught exception
04-26 10:55:39.573: ERROR/AndroidRuntime(1047): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
04-26 10:55:39.573: ERROR/AndroidRuntime(1047):     at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-26 10:55:39.573: ERROR/AndroidRuntime(1047):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:451)
04-26 10:55:39.573: ERROR/AndroidRuntime(1047):     at com.stellent.gorinka.AsyncImageLoaderv.loadImageFromUrl(AsyncImageLoaderv.java:57)
04-26 10:55:39.573: ERROR/AndroidRuntime(1047):     at com.stellent.gorinka.AsyncImageLoaderv$2.run(AsyncImageLoaderv.java:41)
04-26 10:55:40.393: ERROR/dalvikvm-heap(1047): 14600-byte external allocation too large for this process.
04-26 10:55:40.403: ERROR/(1047): VM won't let us allocate 14600 bytes
04-26 10:55:40.493: ERROR/AndroidRuntime(1047): Uncaught handler: thread Thread-93 exiting due to uncaught exception
04-26 10:55:40.493: ERROR/AndroidRuntime(1047): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
04-26 10:55:40.493: ERROR/AndroidRuntime(1047):     at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-26 10:55:40.493: ERROR/AndroidRuntime(1047):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:451)
04-26 10:55:40.493: ERROR/AndroidRuntime(1047):     at com.stellent.gorinka.AsyncImageLoaderv.loadImageFromUrl(AsyncImageLoaderv.java:57)
04-26 10:55:40.493: ERROR/AndroidRuntime(1047):     at com.stellent.gorinka.AsyncImageLoaderv$2.run(AsyncImageLoaderv.java:41)
04-26 10:55:40.594: INFO/Process(584): Sending signal. PID: 1047 SIG: 3

Here's the coding in the adapter...

final ImageView imageView = (ImageView) rowView.findViewById(R.id.image);
        AsyncImageLoaderv asyncImageLoader=new AsyncImageLoaderv();
        Bitmap cachedImage = asyncImageLoader.loadDrawable(imgPath, new AsyncImageLoaderv.ImageCallback() {
            public void imageLoaded(Bitmap imageDrawable, String imageUrl) {

                imageView.setImageBitmap(imageDrawable);
            }
            });
        imageView.setImageBitmap(cachedImage);

To load the image...

public static Bitmap loadImageFromUrl(String url) {
            InputStream inputStream;Bitmap b;
        try {

            inputStream = (InputStream) new URL(url).getContent();
            BitmapFactory.Options bpo=  new BitmapFactory.Options();
            bpo.inSampleSize=2;
             b=BitmapFactory.decodeStream(inputStream, null,bpo );
             return b;
        } catch (IOException e) {
                throw new RuntimeException(e);
            }
           //return null;
     }  

Please tell me how to fix the error....

Rahul Kalidindi
  • 4,666
  • 14
  • 56
  • 92
  • you need try implement code in this link http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object – AnilPatel Apr 24 '13 at 12:50

1 Answers1

1

You are getting OOM Errors because your Bitmap is taking up too much of memory. See if this can help: Handling large Bitmaps. Down sampling the image to half its original size may still result in an image that is just too big for the runtime.

Community
  • 1
  • 1
Samuh
  • 36,316
  • 26
  • 109
  • 116
  • I have tried these methods. The app is running smoothly sometimes but crashing many times displaying the error about the memory ... – Rahul Kalidindi Apr 26 '10 at 10:32