This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Random numbers and arrays 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 » Java » Beginning Java
Bookmark "Random numbers and arrays" Watch "Random numbers and arrays" New topic
Author

Random numbers and arrays

Howard Ralston
Ranch Hand

Joined: Jun 25, 2001
Posts: 105
Howdy folks,
Let's try this again. This is a small program which is "supposed" to generate 3 random numbers from 1 to 6, not allowing any duplicates. Then it should put these numbers into an array of TextFields. It compiles but gives an exception in thread "main" NullPointerException. I figure that there is a problem with one of the arrays, but cannot figure out what the problem is. Any help would be greatly appreciated.
Thanks,
Howard


------------------

<a href="http://www.getlocaldeals.com" target="_blank" rel="nofollow">Free local coupons</a>
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Here is the code...
It took me a while to remember that little thingy about arrays of objects being a little different.
I've also modified the random number generation to be a bit more compact.
Howard Ralston
Ranch Hand

Joined: Jun 25, 2001
Posts: 105
Thanks a lot, Mike. I won't have time to utilize your changes until tomorrow, but suddenly my headache is fading away.
I'm not familiar with the Vector class so this method did not even occur to me. I guess I need to look up the API for it in order to learn more about the provided methods.
Thanks again.
Howard
 
Don't get me started about those stupid light bulbs.
 
subject: Random numbers and arrays
 
Similar Threads
boxing,unboxing,for each and varargs
generics 1.4
help me to clear Jcombo during runtime
Printing in Array in Ascending order
Probability Question