@Override
public void run() {
Canvas canvas;
while (running) {
canvas = null;
try {
canvas = this.surfaceHolder.lockCanvas();
synchronized (surfaceHolder) {
this.gamePanel.update();
this.gamePanel.render(canvas);
}
} finally {
if (!canvas.equals(null)) { // error is here.
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
答案 0 :(得分:1)
如果执行错误
canvas = this.surfaceHolder.lockCanvas();
然后canvas
将是null
。这就是我怀疑这里发生了什么。
更改
if (!canvas.equals(null)) {
到
if (canvas != null) {