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;
}
}
一、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;
}
}
相关文章推荐
- Android JNI使用方法
- android---------ndk中的各个版本的下载地址。
- 当android调试遇到ADB server didn't ACK以及顽固的sjk_daemon进程
- jitsi-android 编译,视频聊天
- 从Android SSH 登陆自己的Ubuntu
- JAVA和android 环境配置
- Socket Programming on Android
- Android四大组件简述之Activit
- Android 切换图片ImageSwitcher
- Android中Activity与Service的交互方式
- Android 开发环境的构建备忘
- Android Parcelable和Serializable的区别
- Phonegap打包Android程序无法实现定位的问题
- PM的自我修养——豌豆荚的Android客户端简要分析
- android sdk又不能更新了,怎么解决
- 高性能Android Canvas游戏开发
- android开发环境搭建问题
- Android 模拟器
- Android开发学习之浅谈显示Intent和隐式Intent
- 完整的android开发环境搭建和源代码编译过程 .