Search code examples
androidout-of-memoryassetsbitmapfactoryandroid-bitmap

Android out of memory exception


please help in solving me this out of memory exception as i am unable to solve it, any help would be greatly appreciated,

06-04 12:11:44.119: E/AndroidRuntime(9090): FATAL EXCEPTION: main
06-04 12:11:44.119: E/AndroidRuntime(9090): Process: com.zar.bdr, PID: 9090
06-04 12:11:44.119: E/AndroidRuntime(9090): java.lang.OutOfMemoryError
06-04 12:11:44.119: E/AndroidRuntime(9090):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-04 12:11:44.119: E/AndroidRuntime(9090):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
06-04 12:11:44.119: E/AndroidRuntime(9090):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
06-04 12:11:44.119: E/AndroidRuntime(9090):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
06-04 12:11:44.119: E/AndroidRuntime(9090):     at android.content.res.Resources.loadDrawable(Resources.java:2113)
06-04 12:11:44.119: E/AndroidRuntime(9090):     at android.content.res.Resources.getDrawable(Resources.java:700)
06-04 12:11:44.119: E/AndroidRuntime(9090):     at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:176)
06-04 12:11:44.119: E/AndroidRuntime(9090):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
06-04 12:11:44.119: E/AndroidRuntime(9090):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
06-04 12:11:44.119: E/AndroidRuntime(9090):     at android.content.res.Resources.loadDrawable(Resources.java:2095)
06-04 12:11:44.119: E/AndroidRuntime(9090):     at android.content.res.TypedArray.getDrawable(TypedArray.java:602)

Solution

  • Solution 1: You can use android:largeHeap="true"in activity's manifest to request a larger heap size, but this will not work on any pre Honeycomb devices.

    Solution 2: Use an Image Loader library like,

    Universal Image Loader

    Which takes all the headache of loading a large image file, also supports some additional feature like caching and converting.