0

I am new to Android area. I have written a Primitive app.

I have a ListView with images and text.

Now I have an error message.

    java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
at android.content.res.Resources.loadDrawable(Resources.java:1709)
at android.content.res.Resources.getDrawable(Resources.java:581)
at android.widget.ImageView.resolveUri(ImageView.java:501)
at android.widget.ImageView.setImageResource(ImageView.java:280)
at com.PACKAGE.MainActivity$MyListAdapter.getView(MainActivity.java:132)
at android.widget.AbsListView.obtainView(AbsListView.java:1432)
at android.widget.ListView.makeAndAddView(ListView.java:1745)
at android.widget.ListView.fillDown(ListView.java:670)
at android.widget.ListView.fillFromTop(ListView.java:727)
at android.widget.ListView.layoutChildren(ListView.java:1598)
at android.widget.AbsListView.onLayout(AbsListView.java:1262)
at android.view.View.layout(View.java:7175)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
at android.view.View.layout(View.java:7175)
at android.widget.FrameLayout.onLayout(FrameLayout.java:343)
at android.view.View.layout(View.java:7175)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
at android.view.View.layout(View.java:7175)
at android.widget.FrameLayout.onLayout(FrameLayout.java:343)
at android.view.View.layout(View.java:7175)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3714)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(Native Method)

What exactly says this error message? In Which line is the error?

How can I best read and understand a message?

halfer
  • 19,824
  • 17
  • 99
  • 186
NewYorker
  • 67
  • 1
  • 8
  • 1
    It means you are working with an image and your image operation exceeds alowed memory size – Ismail Sahin Dec 06 '13 at 17:38
  • 1
    Please avoid using "urgent" in your questions. – Egor Dec 06 '13 at 17:39
  • take a look at here for possible solution http://stackoverflow.com/questions/2928002/outofmemoryerror-bitmap-size-exceeds-vm-budget-android – Ismail Sahin Dec 06 '13 at 17:39
  • maybe android:largeHeap="true" inside the -tag in your AndroidManifest.xml could fix it, otherwise you will have to resize your image or use another workaround. how many images do you use/ what is their resolution? – bbuecherl Dec 06 '13 at 17:41
  • Thank you for the answer. I have 5 images (png 200x200, 8-15kb) and 1 picture 2200x2048 1.61 MB – NewYorker Dec 06 '13 at 18:21
  • You need to implement lazy loading for your images, so that they are loaded in the background. If you are new you might want to use libraries already available to implement the same. Have a look at Picasso here : https://github.com/square/picasso – Adnan Mulla Dec 07 '13 at 11:23

1 Answers1

0

First look at the exception
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
and most probably this is the line in your code
at com.PACKAGE.MainActivity$MyListAdapter.getView(MainActivity.java:132) (notice your package)

You tried to load an image larger than your heap supported. The size in MB of the compressed file is of little importance, as any image will be expanded in memory as a bitmap. Thus only the pixel format and pixel count matters. In your case 2200x2048 might me to much.

As possible solutions for the memory problem

  • Use a lower resolution image, or manually load the image using BitmapFactory where you have the option to downsample
  • Use android:largeHeap="true" in manifest might help. Not good practice, if can be avoided.

The ANR comes because you do a lot of work (loading large image) on the UI thread. Lower resolution image might help also to this problem, but you should consider loading the images in a worker thread
http://developer.android.com/guide/components/processes-and-threads.html, Worker threads

Big
  • 237
  • 2
  • 4