• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Random numbers and arrays

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


------------------
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic