您的位置:首页 > 移动开发 > Android开发

java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@41a7f048

2014-03-09 13:43 627 查看
在android4.2.2系统上运行一款“保龄球”的游戏,无法运行。
一、log

03-07 10:50:49.579 I/dalvikvm-heap( 3131): Grow heap (frag case) to 12.529MB for 4147216-byte allocation
03-07 10:50:49.598 D/dalvikvm( 3131): GC_CONCURRENT freed 3K, 46% free 10447K/19060K, paused 2ms+1ms, total 19ms
03-07 10:50:49.774 D/AndroidRuntime( 3131): Shutting down VM
03-07 10:50:49.774 W/dalvikvm( 3131): threadid=1: thread exiting with uncaught exception (group=0x40ab9930)
03-07 10:50:49.782 E/AndroidRuntime( 3131): FATAL EXCEPTION: main
03-07 10:50:49.782 E/AndroidRuntime( 3131):
java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@41a7f048
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.graphics.Canvas.throwIfRecycled(Canvas.java:1026)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.graphics.Canvas.drawBitmap(Canvas.java:1096)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.graphics.Bitmap.createBitmap(Bitmap.java:617)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.graphics.Bitmap.createBitmap(Bitmap.java:514)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at Com.Coocaa.AhZk.Bowling2.GameView.initPic(GameView.java:273)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at Com.Coocaa.AhZk.Bowling2.GameView.surfaceCreated(GameView.java:536)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.view.SurfaceView.updateWindow(SurfaceView.java:608)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.view.SurfaceView.access$000(SurfaceView.java:86)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:174)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:680)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1842)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.view.Choreographer.doFrame(Choreographer.java:532)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.os.Handler.handleCallback(Handler.java:725)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.os.Looper.loop(Looper.java:137)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at android.app.ActivityThread.main(ActivityThread.java:5233)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at java.lang.reflect.Method.invokeNative(Native Method)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at java.lang.reflect.Method.invoke(Method.java:511)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
03-07 10:50:49.782 E/AndroidRuntime( 3131):     at dalvik.system.NativeStart.main(Native Method)
03-07 10:50:49.793 W/ActivityManager( 1989):   Force finishing activity Com.Coocaa.AhZk.Bowling2/.BowlingIIActivity

二、问题分析
 java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@41a7f048
表示java运行异常:试图使用一个已经回收了的图片。
三、解决方法

public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height,
            Matrix m, boolean filter) {

         
     ...........
             
 ...........

if (!source.isMutable() && x == 0 && y == 0 && width == source.getWidth() &&
                height == source.getHeight() && (m == null || m.isIdentity())) {
        //当传输的Bitmap source传进来的分辨率跟原图片的分辨率相同的时候,也强制创建新的Bitmap
      //这样回收的时候,就回收的是副本。
           // return source;
        }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: