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
-
Whenever I plug my charger into my iPhone more 6 seconds I get a pop that says this accessory may not be recognized and will not take a charge. It is the charger supplied with the phone. But my iPad charger is more than 2 years works great on my phone. What's wrong? And why won't my charger. I also have another charger at work that the phone recognizes even plug me the charger in but that works well on a co-workers phone. Suggestions?
Help here > power adapters using iPad with iPhone, iPad and iPod - Apple Support
-
My browser is running do not. I uninstall, install several times. Uninstall cookies, delete the data from the user, install in another user - no reaction. What's wrong? Help, please
Start Firefox in Safe Mode {web link} by holding down the < shift >
(Mac options) key and then from Firefox. Is always the problem?Start your computer in safe mode with network. Then launch Firefox.
Try the sites secure web. Is always the problem? -
I changed my avatar picture, but it is not displayed in my circle of avatar! What's wrong???
You have to be level 3 before you can have a custom avatar. Keep at it
-
I got a Apple Watch yesterday and since put in place and paired him and everything, but now I can not unlock it or look at anything on the watch because it won't let me. Any ideas as to what is wrong or what I am doing wrong?
Hello
If you have not already done so, it could be that you want to configure your watch with these settings:
-On your iPhone, in the application of Eve, go to: My Watch (tab) > General > detection of wrist - it lights up.
-On your iPhone, in the application of Eve, go to: Watch My > password > code turn on (choose a password Simple or more complex).
-Also on the password settings screen, select Unlock with iPhone.
After putting on your wrist, your watch don't unlock then after whatever you do first: unlock your watch manually (by entering the access code) or unlock your iPhone.
Then, it will remain unlocked (including when the screen is idle) until you remove it from your wrist. When you remove your watch, it locks automatically.
More information:
-
My Icloud account does not work. As soon as I try to connect my PC know "this browser is not supported. What went wrong and what can do? I previously used the same connection to my account for a long time without any problem. My PC I have a tie with Windows 8
< personal information deleted by host >
Hi bengtfrombelgentier,
Welcome to the communities of Apple Support! I'm sorry to hear that you are experiencing these problems access iCloud. If you are unable to access iCloud.com due to an error of supported browser, you can check the browser requirements set out in the following article:
Requirements for iCloud - Apple Support
Concerning
-
WWhen I go to settings > ICloud. When I press ICloud. It doesn't do anything. It is grayed out. What's wrong?
Select this check box. Go to settings > general > Restrictions > allow changes > accounts > turn off.
-
My ipad used to print on my printer HP B210, now, it won't. What's wrong? (iPad 1) Everything is connected correctly, am online and print very well to my HP laptop. The iPad is the printer, but after trying to communicate with her, he says that the printer is offline (i.e. is not)
Hi, I decided to turn off my printer and unplug the unit. Also turned off of my iPad. Waited about 30-60 seconds and plugged into the printer, powered on the iPad. We have lift-off! It works now! Thanks for responding.
-
E HP 4500 printer won't stay on, but for 3-5 seconds. What's wrong?
My printer HP e-4500 will not remain, but 3-5 seconds then turns off. What's wrong? What can I do about it?
[Moved from the community centre of Participation]
Hello
Search HP Support
or post in the Forums of HP.
Don
-
why I can not load Word or adobe my computer let me I can not open my files what is wrong?
Hi marycookexr,
What happens when you try to download or install? You have a Setup for Microsoft Word disk?
Please visit the following link to install Adobe Reader:
In addition, if you do not have the software set to install for Word, please see the following link to install a Word Viewer:
http://www.Microsoft.com/download/en/details.aspx?displaylang=en&ID=4
I hope this helps!
-
What's wrong is tracert report?
Referring to the following picture, I would like to know what's wrong on 1 test with tracert.
Request timed out.
The first connection fails?
Thanks in advance for your suggestions
http://I1093.Photobucket.com/albums/i438/junk000/pinging.jpg
Hello
Try to post your query in the sub category.
http://TechNet.Microsoft.com/en-us/ms772425.aspx
Hope this information is useful.
-
I can't open the speech recognition in Word 2003 - I click on Word under Tools, nothing helps. What's wrong? If I go to the Control Panel, under regional and Language Options, the button is grayed.
Hello Stephen,
Please see the following articles:
How to install and configure speech recognition and handwriting in Word 2003
Using speech recognition for the first time in the Office
Frequently asked questions about speech recognition for office functionality
How to install and configure speech recognition in Windows XP
-
I am running Windows XP sp3, out of nowhere, my computer started to randomly restart. What to do with the tools I have to try to find what is wrong?
Hello ccsmudge,
Often, we see crashes as a result of a program from loading at startup.To solve these, we use the clean boot troubleshooting.The following describes this process:In addition, if you can zip the contents of the c:\Windows\minidump folder and put it on a public folder to http://skydrive.live.com , then we can take a peek to see if and why we are bluescreening and restart all of a sudden.Best regardsMatthew_Ha -
Lexmark Z25 printer has new cartiges, but prints blank. What's wrong?
I just installed my Lexmark Z25 printer on my brand new laptop and replaced by the new ink and the page will pass through white. What's wrong? I tried the test page, clean and even tried to find the driver closest to install it, there seems to be nothing wrong with the printer as well as the payment. Can someone please?
Hello
· What program you are trying to print from?
· The printer was working fine on the system before?
· This happens thanks to a particular application or with the set?
· You can print the test page using the printer without any problems?
· What type of file you want to print?
Method 1:
I suggest to run the troubleshooter printer on the system and check if the problem is resolved.
Printer in Windows problems
http://Windows.Microsoft.com/en-us/Windows/help/printer-problems-in-Windows
I suggest you to uninstall the printer driver and the system software and then reinstall the system again and check if the problem is resolved.
How to manage devices in Windows XP
http://support.Microsoft.com/kb/283658/en-us
http://support.Lexmark.com/index?page=productSelection&UserLocale=en_US&locale=en
I suggest you follow the steps in troubleshooting mentioned in the PDF and see if the problem is resolved.
http://www.Lexmark.com/publications/pdfs/Z25-Z35/Eng/enogmacx.PDF
See also the article mentioned below.
Quick view is empty, the printer prints blank pages or saved pdf is empty at the office for Mac applications
-
When I click on any icon in my control panel, a black window opens and C:WINDOWS\system32\rundll32.exe is what's wrong with the system
{Assuming the rundll32.exe file is not found}
See if them can restore the file rundll32.exe:
http://support.Microsoft.com/kb/812340 Ramesh Srinivasan, Microsoft MVP [Windows Desktop Experience] -
I can sign my msn account, but I can't open my email. What's wrong?
I can sign my msn account, but I can't open my email. What's wrong?
Hello1. what happens when you try to open an e-mail?
2. it happens with a particular message or it comes up with all the emails?
3. have you made recent changes to your computer?Follow the below mentioned article:How to contact MSN customer service:
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
-
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