8

Hi i am creating an app about traffic signs. traffic signs are in .png format. some of them I am showing in horizontalscrollview. But when try to open activities , I get this error from android market error reports. here is my error report:

<java.lang.RuntimeException: Unable to start activity ComponentInfo{com.besalti.svenskavagmarken/com.besalti.svenskavagmarken.varningsmarken}: android.view.InflateException: Binary XML file line #645: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3701)
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:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #645: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:518)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:227)
at android.app.Activity.setContentView(Activity.java:1657)
at com.besalti.svenskavagmarken.varningsmarken.onCreate(varningsmarken.java:25)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at android.view.LayoutInflater.createView(LayoutInflater.java:505)
... 26 more
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:494)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:370)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:715)
at android.content.res.Resources.loadDrawable(Resources.java:1720)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.widget.ImageView.<init>(ImageView.java:122)
at android.widget.ImageView.<init>(ImageView.java:112)
... 29 more>

can anyone help me?

JPM
  • 9,077
  • 13
  • 78
  • 137
Erkan Beşaltı
  • 91
  • 1
  • 1
  • 3
  • Can you show us the code for varningsmarken.java and the layout xml file for it. Apparently you have a Typearray too. Also what is the size of the image that is bein loaded in the imageview? – JPM Oct 24 '11 at 17:01
  • 2
    Post up the fix so that others may learn from you, that is what this site is about...plus I am curioud too. – JPM Nov 02 '11 at 14:27
  • @ErkanBeşaltı please post the fix. – hemanth kumar Feb 12 '13 at 11:07
  • I am facing same issue , please post the fix ! – Ahmed Jun 22 '13 at 15:32

2 Answers2

3

The "bitmap size exceeds VM budget" error is actually in the native graphics library (Skia). It is a tad confusing as the problem is really that Skia has run out of memory in the native heap for bitmap data. See BitmapFactory OOM driving me nuts for background. To get round this, you will have to look carefully at your bitmap usage

  • making sure that you do not leave bitmap references floating
  • doing a recycle / null onn bitmaps as they become free (this appears to help).
Community
  • 1
  • 1
Torid
  • 4,176
  • 1
  • 28
  • 29
2

Use sampling to read bitmap. May be error occurred due to memory leaks.

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;

Bitmap bitmap=BitmapFactory.decodeFile(path,options);
sinelaw
  • 16,205
  • 3
  • 49
  • 80
Sam
  • 322
  • 1
  • 6