Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.lang.NullPointerException

 
Zack Brown
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following Viewer class:



and ViewerTest class:



Both compile. However, when I run the ViewerTest, I get the following errors:

Exception in thread "main" java.lang.NullPointerException
at Viewer.toString(Viewer.java:88)
at ViewerTest.main(ViewerTest.java:6

Does anyone have any ideas? Thanks.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the line numbers in your post match the line numbers in your code, then as the error message tells you, the error on line 88 is here:

So it must be that movieCode is null, since that's the only thing you're dereferencing in that line.
 
Zack Brown
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed the Viewer class code to this:



when I run the following test code:



I get " Jeff Brown DR $336.6" when I should be getting "Jeff Brown DR $5.24" I have checked the calculations in the switch statement and if/else statement and cannot see where the problem lies. Does anyone see what's wrong?
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand why you're multiplying a cost number by a char value extracted from the movie code.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic