• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

NullPointerException occured  RSS feed

 
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
 
Sheriff
Posts: 21502
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fix:



Add this right before:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!