recycled bitmap android

android代码中的问题,注不是imagview的回收问题是textview的回收问题

java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@2e09f030
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1282)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.graphics.Canvas.drawBitmap(Canvas.java:1416)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:539)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.widget.TextView.onDraw(TextView.java:5414)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.View.draw(View.java:15305)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.View.draw(View.java:15214)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewGroup.drawChild(ViewGroup.java:3414)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3205)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.View.draw(View.java:15308)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.View.draw(View.java:15214)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewGroup.drawChild(ViewGroup.java:3414)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3205)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.View.draw(View.java:15212)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewGroup.drawChild(ViewGroup.java:3414)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3205)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.View.draw(View.java:15212)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewGroup.drawChild(ViewGroup.java:3414)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3205)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.View.draw(View.java:15212)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewGroup.drawChild(ViewGroup.java:3414)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3205)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.View.draw(View.java:15308)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.widget.FrameLayout.draw(FrameLayout.java:598)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2674)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2779)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewRootImpl.draw(ViewRootImpl.java:2685)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2425)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2048)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1105)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6204)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:799)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.Choreographer.doCallbacks(Choreographer.java:612)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.Choreographer.doFrame(Choreographer.java:581)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.view.Choreographer$FrameHandler.handleMessage(Choreographer.java:714)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.os.Looper.loop(Looper.java:135)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5669)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at java.lang.reflect.Method.invoke(Native Method)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
08-29 15:43:52.889 26558-26558/com.BDB.bdbconsumer W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

2个回答

你的TextView是不是设置了drawableTop,drawableBottom,,drawableXXX之类的属性,或者在代码中使用了setCompoundDrawables()?
如果这些属性 指向的资源图片不存在,或运行的时候找不到的话,尤其是指向的是android系统中的资源图片,会抛出trying to use a recycled bitmap 这样的异常。
比方说drawableTop指向了@android:drawable/sym_call_missed(android:drawableTop="@android:drawable/sym_call_missed"),
这个资源sym_call_missed不是每个Android版本都有的,如果在测试设备的Android版本没有 这个图片,就会引发 “trying to use a recycled bitmap android.graphics.Bitmap@2e09f030 throwIfCannotDraw "的异常。

如果使用了setCompoundDrawables(..),也有可能setCompoundDrawables(..)中的drawable参数在运行时是null,可以检查一下代码。

说错了一点,请忽略最后一句。setCompoundDrawables(..)中的drawable参数在运行时是null不会引起你遇到的异常。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!