【发布时间】:2017-04-14 12:16:58
【问题描述】:
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)
在“设置壁纸”界面,我旋转了屏幕,重新启动了草图(绘制动态壁纸),应用程序崩溃(并非总是崩溃),而草图(动态壁纸)一直在后台运行。
有人可以给我一个提示吗?提前致谢。
我在 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。
我现在没有这个问题,因为我更新了新版本的处理库..上面的代码来自新版本的库。 (我看不到旧版本的代码)
【问题讨论】:
-
当Animation Thread中的这个NullPointerException被抛出时,如何在android studio中设置断点?
-
我现在没有这个问题,因为我更新了新版本的处理库..
标签: java android canvas nullpointerexception live-wallpaper