
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
我的代码是,
为了从drawable中获取可绘制的动画,
private voID getAnimationForLetters(int mAnim) { // Todo auto-generated method stub String anim = "cAPItal_anim_" + new Integer(mAnim).toString(); final int resID = getApplicationContext().getResources().getIDentifIEr( anim,"drawable","my-package-name"); mimgLetter.clearanimation(); mimgLetter.setBackgroundResource(resID); mimgLetter.post(new Runnable() { public voID run() { loadingAnimation = (AnimationDrawable) mimgLetter .getBackground(); loadingAnimation.start(); } }); } 我的下一个按钮代码是,
case R.ID.btnNext_: unbindDrawables(findVIEwByID(R.ID.imgLetter));mLetterNum=mLetterNum+1;getAnimationForLetters(mLetterNum);
我的undind drawable方法代码是,
private voID unbindDrawables(VIEw vIEw) { if (vIEw.getBackground() != null) { vIEw.getBackground().setCallback(null); } if (vIEw instanceof VIEwGroup) { for (int i = 0; i < ((VIEwGroup) vIEw).getChildCount(); i++) { unbindDrawables(((VIEwGroup) vIEw).getChildAt(i)); } ((VIEwGroup) vIEw).removeAllVIEws(); } } 最后我得到了异常java.lang.OutOfMemoryError:位图大小超过VM预算
它在这里显示异常mimgLetter.setBackgroundResource(resID);
请帮我.
我添加了以下代码来清除,
loadingAnimation.stop(); for (int i = 0; i < loadingAnimation.getNumberOfFrames(); ++i){ Drawable frame = loadingAnimation.getFrame(i); if (frame instanceof BitmapDrawable) { ((BitmapDrawable)frame).getBitmap().recycle(); } frame.setCallback(null); } loadingAnimation.setCallback(null); 它只适用于下一个或上一个.第一次点击下一个动画移动到第二个动画,第二次如果我点击上一个按钮我有异常,
Canvas: trying to use a recycled bitmap androID.graphics.Bitmap
请帮我.
解决方法 确切地说 – 系统知道何时收集垃圾,所以调用它至少没有帮助.你必须真正真正管理你的应用程序内存. 290×330可能看起来不多,但是如果你使用的是每个像素4个字节的完整RGBA,那么你的图像会变成380K.如果你有其中几个,你将会耗尽内存.大多数AndroID设备都不像PC – 它们的内存相当有限.有些只有16M或24M来运行所有内容,包括 *** 作系统和用户可能同时运行的任何其他应用程序.
您可以尝试使用try / catch包装例程来加载资源
While( ! success ) { try { // load resources } catch (OutOfMemoryError E) { // do something to use less memory and try again } } 总结 以上是内存溢出为你收集整理的如何在android中解决OutOfMemoryError?全部内容,希望文章能够帮你解决如何在android中解决OutOfMemoryError?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)