java.lang.RuntimeException:Canvas:尝试使用循环位图,无法跟踪确切位置

时间:2015-09-08 13:15:23

标签: android android-activity bitmap runtimeexception bitmapfactory

在我的应用程序中,我在多个位置/ Activity使用Bitmap,并在相应的活动销毁时回收所有这些。     我已经提到了完整的异常堆栈跟踪,因为仍然使用了回收的Bitmap,但是我无法跟踪该类或位图,因此发生了明显的异常。任何人都可以帮助我如何在我的应用程序中跟踪崩溃的位置

java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@42d3c090
       at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1084)
       at android.view.GLES20Canvas.drawBitmap(GLES20Canvas.java:844)
       at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:490)
       at android.widget.ImageView.onDraw(ImageView.java:1019)
       at android.view.View.draw(View.java:14465)
       at android.view.View.getDisplayList(View.java:13362)
       at android.view.View.getDisplayList(View.java:13404)
       at android.view.View.draw(View.java:14182)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
       at android.view.View.draw(View.java:14468)
       at android.view.View.getDisplayList(View.java:13362)
       at android.view.View.getDisplayList(View.java:13404)
       at android.view.View.draw(View.java:14182)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
       at android.view.View.draw(View.java:14468)
       at android.support.v4.view.ViewPager.draw(ViewPager.java:2156)
       at android.view.View.getDisplayList(View.java:13362)
       at android.view.View.getDisplayList(View.java:13404)
       at android.view.View.draw(View.java:14182)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
       at android.view.View.draw(View.java:14468)
       at android.view.View.getDisplayList(View.java:13362)
       at android.view.View.getDisplayList(View.java:13404)
       at android.view.View.draw(View.java:14182)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
       at android.view.View.draw(View.java:14468)
       at android.view.View.getDisplayList(View.java:13362)
       at android.view.View.getDisplayList(View.java:13404)
       at android.view.View.draw(View.java:14182)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
       at android.view.View.getDisplayList(View.java:13357)
       at android.view.View.getDisplayList(View.java:13404)
       at android.view.View.draw(View.java:14182)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
       at android.view.View.getDisplayList(View.java:13357)
       at android.view.View.getDisplayList(View.java:13404)
       at android.view.View.draw(View.java:14182)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
       at android.view.View.draw(View.java:14468)
       at android.widget.FrameLayout.draw(FrameLayout.java:472)
       at android.view.View.getDisplayList(View.java:13362)
       at android.view.View.getDisplayList(View.java:13404)
       at android.view.View.draw(View.java:14182)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
       at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:769)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
       at android.view.View.getDisplayList(View.java:13357)
       at android.view.View.getDisplayList(View.java:13404)
       at android.view.View.draw(View.java:14182)
       at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
       at android.view.View.draw(View.java:14468)
       at android.widget.FrameLayout.draw(FrameLayout.java:472)
       at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2326)
       at android.view.View.getDisplayList(View.java:13362)
       at android.view.View.getDisplayList(View.java:13404)
       at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1570)
       at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1449)
       at android.view.ViewRootImpl.draw(ViewRootImpl.java:2377)
       at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2249)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1879)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
       at android.view.Choreographer.doCallbacks(Choreographer.java:574)
       at android.view.Choreographer.doFrame(Choreographer.java:544)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
       at android.os.Handler.handleCallback(Handler.java:733)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5034)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
       at dalvik.system.NativeStart.main(NativeStart.java)

这是我第一次发帖/提问,所以请忽略语言。

1 个答案:

答案 0 :(得分:0)

编写以下代码以防止在画布中使用位图时出现此类异常。

if (mBitmap != null && !mBitmap.isRecycled()) {
    //Write code to show bitmap to canvas
}else{
    //write code to recreate bitmap from source
    //Write code to show bitmap to canvas
}