Out of memory error

Posted by Rahul Varma on Stack Overflow See other posts from Stack Overflow or by Rahul Varma
Published on 2010-04-26T05:37:33Z Indexed on 2010/04/26 5:43 UTC
Read the original article Hit count: 271

Filed under:

Hi, 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....

© Stack Overflow or respective owner

Related posts about android