04-14 12:04:30.971 1639-1938/system_process I/WindowManager: Destroying surface Surface(name=Media:com.android.wallpaper.livepicker/com.android.wallpaper.livepicker.LiveWallpaperChange) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.WindowManagerService.removeWindowLocked:2436 com.android.server.wm.WindowManagerService.removeWindowLocked:2305 com.android.server.wm.WindowManagerService.removeWindow:2300 com.android.server.wm.Session.remove:193
04-14 12:04:30.990 3852-3852/tianranwang.livewallpaper D/MainService: dispose
04-14 12:04:31.018 1639-1990/system_process I/WindowManager: Destroying surface Surface(name=tianranwang.livewallpaper.MainService) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.WindowManagerService.removeWindowLocked:2436 com.android.server.wm.WindowManagerService.removeWindowLocked:2305 com.android.server.wm.WindowManagerService.removeWindow:2300 com.android.server.wm.Session.remove:193
--------- beginning of crash
04-14 12:04:31.020 3852-4240/tianranwang.livewallpaper E/AndroidRuntime: FATAL EXCEPTION: Animation Thread
Process: tianranwang.livewallpaper, PID: 3852
java.lang.NullPointerException: Attempt to invoke interface method 'void android.view.SurfaceHolder.unlockCanvasAndPost(android.graphics.Canvas)' on a null object reference
at processing.a2d.PGraphicsAndroid2D.endDraw(Unknown Source)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PSurfaceNone.callDraw(Unknown Source)
at processing.core.PSurfaceNone$AnimationThread.run(Unknown Source)
在界面中的“设置壁纸”,我旋转屏幕和草图(绘画动态壁纸)重新启动,应用程序坠毁(并不总是崩溃),和素描(动态壁纸)保持在背景上运行..Android动态Wallpaer崩溃(空指针异常,画布是一个空对象),但我找不到在哪里
有人可以给我一个提示吗?提前致谢。
的源代码,即我已经在processing.a2d.PGraphicsAndroid2D.endDraw()
从https://github.com/processing/processing-android/tree/master/core/src/processing
public void endDraw() {
if (bitmap == null) return;
// hm, mark pixels as changed, because this will instantly do a full
// copy of all the pixels to the surface.. so that's kind of a mess.
//updatePixels();
// if (primaryGraphics) {
// if (canvas != null) {
// parent.getSurfaceHolder().unlockCanvasAndPost(canvas);
// }
// }
if (primaryGraphics) {
SurfaceHolder holder = parent.getSurface().getSurfaceHolder();
if (holder != null) {
Canvas screen = null;
try {
screen = holder.lockCanvas(null);
if (screen != null) {
screen.drawBitmap(bitmap, new Matrix(), null);
}
} finally {
if (screen != null) {
try {
holder.unlockCanvasAndPost(screen);
} catch (IllegalStateException ex) {
}
}
}
}
} else {
// TODO this is probably overkill for most tasks...
loadPixels();
}
// Marking as modified, and then calling updatePixels() in
// the super class, which just sets the mx1, my1, mx2, my2
// coordinates of the modified area. This avoids doing the
// full copy of the pixels to the surface in this.updatePixels().
setModified();
super.updatePixels();
}
发现上面的代码可能会导致此的NullPointerException。
我现在没有这个问题,因为我更新处理库的新版本..而上面的代码是从新版本的lib。 (我看不到旧版本的代码)
如何设置在Android Studio中断点,当这个NullPointerException异常在动画线程被抛出? – TrW236
我现在没有这个问题,因为我更新处理库的新版本.. – TrW236