Hi...I posted this earlier but i guess it was too much of code to view. Here, is a simplified version. i really need help here. So pleeease help. The first time the if(A) block is executed flag is true (defined globally as boolean and initialised to true). It gets set to false within the "if(flag)" block. So the second time the "if(A)" block is executed i want the else portion to be executed. The else portion does not get entered into at all. What is happening here?
Marilyn added code tags for readability
[This message has been edited by Marilyn deQueiroz (edited April 25, 2001).]
What do you mean by the 2nd time? Is it within a loop or something. If it's not, then the else part will not be entered. Because the static variable is getting initialized to tru every time. If it's in a loop, then I don't see why the else part is not executed, based on the code you posted. Bosun
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Joined: Apr 25, 2001
Actually commands are being sent to a device. This particular command is sent to the device whenever the suer clicks on a button. The A in "if(A)" denotes the command that is being sent...i.e (if msg.equals ("\ts")) to be precise where ts is the command. So when i say second time, I mean the second time the button is clicked to send this command to the device. The flag ise set globally to true. So the first time the first if statement i.e "if(flag) works" perfectly. The flag also gets set to false. Ao, now when the command is sent again i.e when the "if(A)" block is entered again, flag is false and so the else part must be executed but this doesn't happen. Where am I going wrong here?? Thanks -Shree
Hi Shree, I am not really sure that I understand what you are doing but I definitly don't understand what you mean by 'global'. That is a C terminology that Java doesn't support. I think maybe that is your problem. If the flag is an instance variable then each object would have its' own flag and that would explain why it looks like it never gets set. If you want to use one boolean flag for all objects of the same class then make it static and that should allow anyone to alter it and all others to honor the change. Regards, Manfred.