## Recommended Posts

Hello, My Timer seems to always stop whenever I call a display.setCurrent(something);, where display is of type Display. Here's how the code looks like (modified for brevity):
public void startApp() {
t = new TextBox("ABC", " ", 128, TextField.ANY);

t.setCommandListener(this);

display.setCurrent(t);

iTimer = new Timer();
...
...
...
}

startApp() created my iTimer, and it works fine. I System.out.println() inside taskUpdateMsg's run() method and it does show up as scheduled. And then I do this:
public void commandAction(Command c, Displayable s) {
myList = new List("My List", List.IMPLICIT);

myList.setCommandListener(this);

display.setCurrent(myList);
}

...
...
...
}
when it reaches display.setCurrent(myList), the timer stops...but when I try to create it again, I get an error that says something like it's been created or something exception. Why is this occuring whenever I call Display.setCurrent()? Thanks.

##### Share on other sites
shmoove    821
It shouldn't be stopping.

But what exactly are you doing in the TimerTask's run() method? Maybe changing the current Displayable affects it's execution and somehow makes it throw an Exception or something?

shmoove

##### Share on other sites
marcels    118
I also had the same problem, nothing unusual in run method..

actually I was calling display.setCurrent(new MyGameCanvas());

and the timers was only called once..

now I do:

MyGameCanvas c=new MyGameCanvas();
display.setCurrent(c);
c.init();

##### Share on other sites
nope, nothing in the run() method can cause it to throw an exception...:(

I'll look into your solution/suggestion Marcel.

is this a bug in j2me?

thanks.

##### Share on other sites
marcels    118
don´t know if this is bug in j2me, this happened in the emulator, but I can´t remember if I also tested in the cell phone also.

I didn´t waste much time with this, I found a work around and it´s fine by me

##### Share on other sites
well that's mighty odd...i used kxml and modified/fixed its code (its binary xml implementation is BUGGY!), and this timertask problem does not happen anymore...

i never got exception, etc. before or even now (i also have one in the timertask run() method)...the fix on kxml had nothing to do with anything outside of kxml (other than the text it spews out when i call getText())...

hmm....