What's wrong?

Hi all

I am a beginner on the Blackberry app front... I created a simple application that generated six random numbers and displays them on the screen with a slight delay between each number.

The problem is that after the application is open, closed and then opened again a few times you go to reopen the app and the device or the Simulator just hangs. I'm guessing that its a kind of memory problem or thread. Could you possibly have a look at my code below and see if something obvious is the cause? Thank you Tim

public class Lotto extends UiApplication{

  public static void main(String [] args){
    Lotto theApp = new Lotto();
    theApp.enterEventDispatcher();
  }

  public Lotto(){
    pushScreen(new LottoGenerator());
  }

}

class LottoGenerator extends MainScreen{

 int currentNumber;
 int theArray[] = new int[6];
 int pos = 0;
 TextField genNumber; 

 public LottoGenerator(){

    LabelField number = new LabelField("Lottery Generator - Good Luck!!", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
    genNumber = new TextField();

    add(number);
    add(genNumber);

    Random _test = new Random(System.currentTimeMillis());

    for(int i = 0; i < theArray.length; i++){
      //loops six times to get 6 numbers

      //generate new number

      boolean validNumber = true;
      boolean;

      while(!checked){

    currentNumber = _test.nextInt(48);
    currentNumber += 1;

    for(int j = 0; j < theArray.length; j++){
      if(theArray[j] == currentNumber){
        validNumber = false;
      }
    }

    if(validNumber == false){;
    } else {
      checked = true;
      theArray[pos] = currentNumber;
      pos++;
    }

      } // end of while !checked

    } // end of for loop

    sortTheNumbers();

    new UpdateThread().start();
  }

  public void sortTheNumbers(){

    int a, b;

    for(int i = 0; i < theArray.length; i++){

      for(int j = 0; j < theArray.length-1; j++){
    a = theArray[j];
    b = theArray[j+1];

    if(a > b){
      theArray[j] = b;
      theArray[j+1] = a;
    }
      }

    }

  }

  public boolean onClose(){

    theArray = null;
    System.exit(0);
    this.close();
    return true;
  }

  class UpdateThread extends Thread{

     public void run(){

       try {

    String outputText = "";

        for(int i = 0; i < theArray.length; i++){
       sleep(1050);
       outputText += theArray[i] + " ";
       genNumber.setText("" + outputText);
    }
       } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     System.exit(0);
       }
     }

  }
}

Have not tested, but looking at your code, after

{while(!checked)}

I think you need to add the line

validNumber = true;

otherwise your code will go in a loop, as soon as the random number generator gives you a duplicate.

Tags: BlackBerry Developers

Similar Questions

Maybe you are looking for

  • Cannot create or delete accounts, or download messages

    For no reason that I can discern, TBird stopped to receive or send messages. I even went back to my Beta version to install 38.4.0. I also found that I can not remove or add accounts. The Actions of account in the account page shows settings remove t

  • Volume buttons

    As of today, my F6, F7 and F8 volume buttons stopped to change the volume, how can it be fixed?

  • Firefox did not work in Win XP SP3

    Firefox did not work in Win XP SP3 User Agent Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729;. AskTB5.6)

  • Bootloader screen always loadson Satellite A305-S6909

    My Satellite A305-S6909 still load the Boot Manager screen. I don't have to press F12. Once I press on enter to Hdd it loads then. Yesterday however started the signal strong when I chose the HARD drive. No idea how to fix?

  • T420 how to turn on graphics card

    Hello I was experimenting with configuratition in windows 7 and I turnd off the coast of the graphics card. Now when I turn the t420 screen is black boot. I tried to get into the bios with the f1, but the screen is all black too. How can I activate g