错误致命异常:线程-111

时间:2016-01-25 14:13:43

标签: android

@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);
            }
        }   
    }
}

1 个答案:

答案 0 :(得分:1)

如果执行错误

canvas = this.surfaceHolder.lockCanvas();

然后canvas将是null。这就是我怀疑这里发生了什么。

更改

if (!canvas.equals(null)) {

if (canvas != null) {