• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException occured

 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did some research on my exception I found, but I cant figure out how to solve the issue.

my error:



C:\Documents and Settings\ben\Desktop\park>java BenHultinProg7
Exception in thread "main" java.lang.NullPointerException
at Prog7.<init>(Prog7.java:32)
at BenHultinProg7.main(BenHultinProg7.java:12)

C:\Documents and Settings\ben\Desktop\park>



here is my driver class:




here is my driven class:




Thanks a lot for the help
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The NPE says exactly which line is causing it: Line 32 of Prog7.java. In this case, it's The reason? You never assign anything to field1. Or any of the other fields, for that matter.
 
Christiaan Lombard
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fix:



Add this right before:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic