Exception in thread "main" java.lang.NullPointerException
Here's the code:
What's wrong? This is my first program in Java so it's probably something simple...
Brian Legg wrote:Correct me if I'm wrong but won't the line "ship[i].placeShip(); " also throw an error for accessing a non-static method of a different class from a static context? You'd either have to make placeShip() a static method or fully qualify the call with the class name.
You're wrong, so here's the correction
ship[i] is a reference to a Ship object, so you can call its instance methods on it. However, as Henry already said, the reference is still null and that's causing the problem.