my dog learned polymorphism*
The moose likes Java Micro Edition and the fly likes commandAction - newbie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "commandAction - newbie" Watch "commandAction - newbie" New topic
Author

commandAction - newbie

Arnab Sen
Greenhorn

Joined: Dec 25, 2003
Posts: 20
Hi,

Can anyone tell me what am I doing wrong here ?

The program compiles and runs perfectly but the commandAction is being called repeatedly.

I am using the WTK2.2 final version.




Regards,
Arnab
[ February 04, 2005: Message edited by: Arnab Sen ]
Arnab Sen
Greenhorn

Joined: Dec 25, 2003
Posts: 20
Oh and yes, I am using J2SE 5.0

Regards,
Arnab
Arnab Sen
Greenhorn

Joined: Dec 25, 2003
Posts: 20
Is this some kind of BUG in WTK ? I have been looking everywhere to understand this problem but it seems that commandAction is invoked only when any button is pressed.

So if I select a command once, commandAction will be onvoked only once.

But I can see that the commandAction is being called continuously.

Any pointer please ?

Regards,
Arnab
Yuri Magrisso
Ranch Hand

Joined: Sep 13, 2003
Posts: 58
As far as I see after you press 'ok' on the form you will get on the console:

insiide ok
iinside ok after Alert is displayed

Then you will see the alert and every time you press 'ok' on the alert you will see the same two lines and the alert will stay on-screen. This is because you do not take a different action based on which display you are in.


Yuri
Arnab Sen
Greenhorn

Joined: Dec 25, 2003
Posts: 20
Hi Yuri,

Thanks for your reply.

That's right. I am supposed to see those 2 printlns everytime I press OK. But as I had mentioned, these statements are being printed continuously even without pressing ANYTHING.

Regards,
Arnab
Arnab Sen
Greenhorn

Joined: Dec 25, 2003
Posts: 20
I mean continuously being printed even without pressing ANYTHING!

Arnab
Yuri Magrisso
Ranch Hand

Joined: Sep 13, 2003
Posts: 58
I ran it in WTK 2.1 - when I press 'ok' in the form I get the two lines printed twice. Then each time I press ok in the alert the two lines get printed once.
Next I changed the code in commandAction as I wrote it in my previous post and what happens when I press 'ok' in the form is that it goes to the alert (I see
'iinside ok after Alert is displayed') and then it immediately shows the form again. It looks like if you use the same Command in the form and the alert it gets 'clicked' automatically after you change the display.

Probably you should use different instances of Command.

Yuri
[ February 06, 2005: Message edited by: Yuri Magrisso ]
Yuri Magrisso
Ranch Hand

Joined: Sep 13, 2003
Posts: 58
Ok, I tried with different instances of Command and I am still getting the same result. Obviously the Command in the alert gets 'clicked' automatically anyway.
Quite strange...
Arnab Sen
Greenhorn

Joined: Dec 25, 2003
Posts: 20
Hi Yuri,

Found the problem. Its to do with Alert Timeout. I guess by default Alert is called after every few seconds.

WHen I changed the Alert Timeout value to FOREVER, then the problem is resolved.

This problem will not happen with anything else e.g. with Forms etc...

Regards,
Arnab
Yuri Magrisso
Ranch Hand

Joined: Sep 13, 2003
Posts: 58
Nice to know
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: commandAction - newbie
 
Similar Threads
easy fundamental oop problem
Current focused item in the form
choicegroup not gettin displayed
my .jar didn't run well
suggestions required for J2ME