我的程序出现错误。该错误似乎表明当我在绘制序列结束时尝试将其解锁时,我的表面未锁定。但是如下面的代码所示。我确实首先锁定了表面。为什么我会收到此错误。我做错了什么?
给出错误的方法:
错误行' **this.holder.unlockCanvasAndPost(canvas);**
'
public void run() {
while (this.drawFlag) {
Canvas canvas = this.holder.lockCanvas();
canvas.drawColor(Color.rgb(168, 201, 187));
switch (this.sceneFlag) {
case -1:
draw(canvas);
drawHow(canvas);
drawStr(canvas);
break;
case 0:
draw(canvas);
drawStr(canvas);
break;
case 1:
update();
draw(canvas);
if (this.timeAttackFlag && this.optionNum == 0) {
this.sceneFlag = 2;
try {
setScore();
} catch (Exception e) {
}
} else {
this.holder.unlockCanvasAndPost(canvas);
}
break;
case 2:
drawResult(canvas);
break;
}
this.holder.unlockCanvasAndPost(canvas);
try {
TimeUnit.NANOSECONDS.sleep(this.fpsM.state());
} catch (Exception e_2) {
}
}
}
日志猫:
05-25 19:12:14.091: E/AndroidRuntime(21305): FATAL EXCEPTION: Thread-6886
05-25 19:12:14.091: E/AndroidRuntime(21305): Process: com.gordondev.smackitup, PID: 21305
05-25 19:12:14.091: E/AndroidRuntime(21305): java.lang.IllegalStateException: Surface was not locked
05-25 19:12:14.091: E/AndroidRuntime(21305): at android.view.Surface.unlockCanvasAndPost(Surface.java:268)
05-25 19:12:14.091: E/AndroidRuntime(21305): at android.view.SurfaceView$4.unlockCanvasAndPost(SurfaceView.java:852)
05-25 19:12:14.091: E/AndroidRuntime(21305): at com.gordondev.smackitup.GameView.run(GameView.java:858)
05-25 19:12:14.091: E/AndroidRuntime(21305): at java.lang.Thread.run(Thread.java:841)