Chirag_CID
Chirag_CID

Reputation: 2224

bitmap size exceeds VM budget...how to solve this error?

I have gone through so many posts related to this error but not getting proper solution for my problem. there are three activities in my projec..in each acivity there are 4 animations for which i am using sequences. on onclick to change my activity i am getting vm budget out of memory error. How to clear memory of an acivity while we are going to other activity? so that memory could be used for next activity.. thanks in advance for help...

Error occuring is as below....

09-10 10:35:12.046: ERROR/AndroidRuntime(472): FATAL EXCEPTION: main
09-10 10:35:12.046: ERROR/AndroidRuntime(472): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.graphics.Bitmap.nativeCreate(Native Method)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.content.res.Resources.loadDrawable(Resources.java:1709)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.content.res.Resources.getDrawable(Resources.java:581)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:265)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:788)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.content.res.Resources.loadDrawable(Resources.java:1694)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.content.res.Resources.getDrawable(Resources.java:581)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.view.View.setBackgroundResource(View.java:7393)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at com.bokstverna.InnerActivityR.onCreate(InnerActivityR.java:87)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.os.Looper.loop(Looper.java:123)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at java.lang.reflect.Method.invokeNative(Native Method)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at java.lang.reflect.Method.invoke(Method.java:521)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-10 10:35:12.046: ERROR/AndroidRuntime(472):     at dalvik.system.NativeStart.main(Native Method)

Upvotes: 1

Views: 449

Answers (1)

Jyosna
Jyosna

Reputation: 4446

U have to scale ur bitmap like below,

img.setImageBitmap(Bitmap.createScaledBitmap(bitmap, 200,200, true));

then its size will not exceed.It will fix to a particular size.

Upvotes: 2

Related Questions