11-20-2012 05:21 AM - edited 11-20-2012 05:33 AM
hi all,
mbytes= 350
Longreadnumberofkbytes= 250
readalert1file=90 //Text file data
DataLimit= 300 //Text file data
CurrentNumberofDataUsed= mbytes-Longreadnumberofkbytes;
ButtonField Save = new ButtonField ("Save",ButtonField.FOCUSABLE);
FieldChangeListener Listener = new FieldChangeListener() {
public void fieldChanged(Field field, final int context) {
ButtonField Button = (ButtonField) field;
if (Button.getLabel().equals("Save")){
MCBT = new Thread(MakeChangesBackgroundThread);
MCBT .start();
}
}
}
Save.setChangeListener(Listener);
add(Save);
private Runnable MakeChangesBackgroundThread = new Runnable(){
public void run(){
while(true){
long datalimitsum1 = Longreadalert1file/100;
long finalansweralert1= datalimitsum1* LongDataLimit;
if(!(readalert1file==null)){
if(!(readalert1file.equals(""))){
if(finalansweralert1==CurrentNumberofDataUsed && CurrentNumberofDataUsed==finalansweralert1){
synchronized(UiApplication.getEventLock()){
System.out.println("Dialog thread starting");
UiEngine ui = Ui.getUiEngine();
Screen screen = new Dialog(Dialog.D_OK, "You Have Reached You'r "+readalert1file+"% alert",Dialog.OK, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION),Man ager.VERTICAL_SCROLL);
ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_QUEUE);
}try{
Thread.sleep(30000/2);
}catch (InterruptedException e){
e.printStackTrace();
}
}else{
}
}else{
}
}else{
}
}
}
}
My Above code should push the global dialog when the
finalansweralert1
is equal to 270. Can anyone please tell me What I am doing wrong?? TheDialog displays imediately after pushing the save button and not when
finalansweralert1
is equal to
CurrentNumberofDataUsed
Thank you
Solved! Go to Solution.
11-21-2012 05:18 AM
If I understand this correctly, your question seems to be a straight Java question. You have this statement:
if(finalansweralert1==CurrentNumberofDataUsed && CurrentNumberofDataUsed==finalansweralert1){
and you think that CurrentNumberofDataUsed is 270 and finalansweralert1 is 0, and so the if should not be executed.
Is this a correct statement of the problem?
To find out what is wrong with your logic, can you not just put a break point on the if statement and check what the values are?
11-21-2012 05:37 AM
hi peter,
Some of my variables values werent correct they were displaying 0. Fixed it now.
Thank you
11-21-2012 05:42 AM
Can you please mark as solved then?
And perhaps try the debugging trick before posting?
Cheers
11-21-2012 05:44 AM
I was stuck for two days on end, luckily a developer at the office was kind enough to assist me. i have marked the thread as solved. I only post something if i am stuck for days on end.
11-21-2012 05:50 AM
I understand that, but there is a huge difference between being stuck because the Java API is not doing what you expect and stuck because you have a logic error in your code. The debugger is a a powerful tool for helping you trace logic errors, I was suggesting that you get familiar with that so that you do not have to post logic problems here again that could be solved using the debugger. And you won't be stuck for days before posting.... Win for all! Hope that is clear. Cheers
11-21-2012 05:52 AM
okay, Thanks peter. have a good one.