Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • 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: 9273
78
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!
 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic