0

嗨,我正在尝试显示一个显示计时器的 labelField...当单击按钮时计时器应该启动,因此以下代码位于 fieldChanged 自动生成的方法中,因为我实现了 FieldChangeListener...这是代码:

Timer t = new Timer();
Date startTime = new Date();
LabelField courseTime = new LabelField()
t.schedule(new TimerTask(){

public void run() {
// TODO Auto-generated method stub
Date now = new Date();
SimpleDateFormat date = new SimpleDateFormat("HH:mm:ss");
courseTime.setText(date.formatLocal(now.getTime() - startTime.getTime()));
}}, 0, 10);

这段代码有两个问题:当我单击按钮时,我有一个 IllegalStateException.. 不知道它来自哪里,但我已经评论了这个部分,它来自这里.. 然后,在我接受异常之后,计时器开始,但格式是 19:00:00,而不是我希望的 00:00:00……感谢您的帮助!

4

1 回答 1

0

Any operation involving the device's user interface must be done with the lock, UiApplication.getEventLock() held.

Try following code for updating LabelField text.

synchronized (UiApplication.getEventLock()) {
    courseTime.setText("some text");
}
于 2012-05-17T18:57:21.190 回答