开发者

blackberry trying to create a count down timer and exception gets thrown when text is updated

I’m trying to create a count down timer. I user a Timer o开发者_开发百科bject that is given a timertask. I have a label field called mTimerDisplay that is a static member of a class I call cGlobols.

On the run method, that gets called by the timer, can change the color of the label fine:

cGlobals.mTimerDisplay.setBackground(
    BackgroundFactory.createSolidBackground(0xff0000));

When I add the following line:

cGlobals.mTimerDisplay.setText("Hi");

it throws a IllegalStateException: I looked this up and it says

Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation.,

Does this mean I cannot do this operation on the thread, but if so why can I change the color? If I cannot do this on the timer thread, is there another way to do this?


A worker thread cannot update the UI without attaining the event thread. Wrap the setText() invocation in a synchronized block, and use Application.getEventLock() to attain this lock.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜