Two Laptop Bag*
The moose likes Beginning Java and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main" java.lang.NullPointerException" Watch "Exception in thread "main" java.lang.NullPointerException" New topic
Author

Exception in thread "main" java.lang.NullPointerException

Zack Brown
Greenhorn

Joined: Mar 18, 2012
Posts: 2
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Mar 18, 2012
Posts: 2
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
Bartender

Joined: Oct 14, 2005
Posts: 18168
    
    8

I don't understand why you're multiplying a cost number by a char value extracted from the movie code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" java.lang.NullPointerException
 
Similar Threads
How do I get one program to take information out of another one.
Switch error
String index out of range: 1
If/Else/Switch Statements
Null pointer Exception error