java - android VM won't let us allocate 10458756 bytes Error on setBackgroundResource of Button -
i want change image of button on click. button looks "clicked"
, "not clicked"
button image size not big:164 kb
my code worked fine android version 2.3.3
on latest versions started errors
i have read lot of stuff in internet , still can't find answer.
@override public boolean ontouch(view v, motionevent event) { if(event.getaction() == (motionevent.action_up)){ //do whatever want after press center_button.setbackgroundresource(r.drawable.button); } if(event.getaction() == (motionevent.action_down)){ //do whatever want during press //((bitmapdrawable)center_button.getdrawable()).getbitmap().recycle(); center_button.setbackgroundresource(r.drawable.clicked); count++; } return false;
i have tried following things , didn't help:
((bitmapdrawable)center_button.getdrawable()).getbitmap().recycle();
before changing image- changing imagebutton
- adding destroy method recycle
errors:
11-11 20:09:18.305: d/dalvikvm(932): gc_external_alloc freed 19k, 52% free 2605k/5379k, external 12929k/14977k, paused 43ms 11-11 20:09:18.625: d/dalvikvm(932): gc_external_alloc freed 10k, 52% free 2594k/5379k, external 17468k/19516k, paused 29ms 11-11 20:09:18.645: e/dalvikvm-heap(932): 10458756-byte external allocation large process. 11-11 20:09:18.675: e/graphicsjni(932): vm won't let allocate 10458756 bytes 11-11 20:09:18.675: d/dalvikvm(932): gc_for_malloc freed 0k, 52% free 2594k/5379k, external 17468k/19516k, paused 17ms 11-11 20:09:18.675: d/androidruntime(932): shutting down vm 11-11 20:09:18.675: w/dalvikvm(932): threadid=1: thread exiting uncaught exception (group=0x40015560) 11-11 20:09:18.695: e/androidruntime(932): fatal exception: main 11-11 20:09:18.695: e/androidruntime(932): java.lang.outofmemoryerror: bitmap size exceeds vm budget 11-11 20:09:18.695: e/androidruntime(932): @ android.graphics.bitmap.nativecreate(native method) 11-11 20:09:18.695: e/androidruntime(932): @ android.graphics.bitmap.createbitmap(bitmap.java:477) 11-11 20:09:18.695: e/androidruntime(932): @ android.graphics.bitmap.createbitmap(bitmap.java:444) 11-11 20:09:18.695: e/androidruntime(932): @ android.graphics.bitmap.createscaledbitmap(bitmap.java:349) 11-11 20:09:18.695: e/androidruntime(932): @ android.graphics.bitmapfactory.finishdecode(bitmapfactory.java:498) 11-11 20:09:18.695: e/androidruntime(932): @ android.graphics.bitmapfactory.decodestream(bitmapfactory.java:473) 11-11 20:09:18.695: e/androidruntime(932): @ android.graphics.bitmapfactory.decoderesourcestream(bitmapfactory.java:336) 11-11 20:09:18.695: e/androidruntime(932): @ android.graphics.drawable.drawable.createfromresourcestream(drawable.java:697) 11-11 20:09:18.695: e/androidruntime(932): @ android.content.res.resources.loaddrawable(resources.java:1709) 11-11 20:09:18.695: e/androidruntime(932): @ android.content.res.resources.getdrawable(resources.java:581) 11-11 20:09:18.695: e/androidruntime(932): @ android.view.view.setbackgroundresource(view.java:7533) 11-11 20:09:18.695: e/androidruntime(932): @ com.lyuhanan.button.mainactivity$1.ontouch(mainactivity.java:93) 11-11 20:09:18.695: e/androidruntime(932): @ android.view.view.dispatchtouchevent(view.java:3881) 11-11 20:09:18.695: e/androidruntime(932): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:869) 11-11 20:09:18.695: e/androidruntime(932): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:869) 11-11 20:09:18.695: e/androidruntime(932): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:869) 11-11 20:09:18.695: e/androidruntime(932): @ com.android.internal.policy.impl.phonewindow$decorview.superdispatchtouchevent(phonewindow.java:1691) 11-11 20:09:18.695: e/androidruntime(932): @ com.android.internal.policy.impl.phonewindow.superdispatchtouchevent(phonewindow.java:1125) 11-11 20:09:18.695: e/androidruntime(932): @ android.app.activity.dispatchtouchevent(activity.java:2096) 11-11 20:09:18.695: e/androidruntime(932): @ com.android.internal.policy.impl.phonewindow$decorview.dispatchtouchevent(phonewindow.java:1675) 11-11 20:09:18.695: e/androidruntime(932): @ android.view.viewroot.deliverpointerevent(viewroot.java:2194) 11-11 20:09:18.695: e/androidruntime(932): @ android.view.viewroot.handlemessage(viewroot.java:1878) 11-11 20:09:18.695: e/androidruntime(932): @ android.os.handler.dispatchmessage(handler.java:99) 11-11 20:09:18.695: e/androidruntime(932): @ android.os.looper.loop(looper.java:123) 11-11 20:09:18.695: e/androidruntime(932): @ android.app.activitythread.main(activitythread.java:3683) 11-11 20:09:18.695: e/androidruntime(932): @ java.lang.reflect.method.invokenative(native method) 11-11 20:09:18.695: e/androidruntime(932): @ java.lang.reflect.method.invoke(method.java:507) 11-11 20:09:18.695: e/androidruntime(932): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 11-11 20:09:18.695: e/androidruntime(932): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 11-11 20:09:18.695: e/androidruntime(932): @ dalvik.system.nativestart.main(native method) 11-11 20:09:30.735: i/process(932): sending signal. pid: 932 sig: 9
i changed vm number in android emulator 32 320 , working now. still don't understand why failed before.
Comments
Post a Comment