• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Getting an error with a game I created after reading chap 3.

 
Ranch Hand
Posts: 186
1
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings everyone, with some of the material I learned (though I had to research how to do random number generation). I created a mini Craps game (it's a dice game). Unfortunately, even though the program compiles, it refuses to run. Here is the error I'm getting:

lamoubeldum@LamouBeldum:~/JavaPrograms/Projects$ java CrapsTest
Exception in thread "main" java.lang.NullPointerException
at CrapsTest.main(CrapsTest.java:12)
lamoubeldum@LamouBeldum:~/JavaPrograms/Projects$

Here is my code, everything compiles just fine:




Is there anything I'm not seeing, maybe you Java Heroes can shed some light on the situation Thanks!

 
Saloon Keeper
Posts: 9556
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This creates an array of references but until you initialize them the references are null;
You'll need something like
 
Naziru Gelajo
Ranch Hand
Posts: 186
1
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:
This creates an array of references but until you initialize them the references are null;
You'll need something like



Excellent, thank you very much!
 
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic