Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

David Eskin
David Eskin
754 Points

Need Help Debugging (java.lang.NullPointerException)

I have spent hours trying to find the source of this bug and I am at a loss. Please see link for the relevant files. Point.java, Ocean.java and Trial.java. Main is in Trial.java.

Also in Ocean.java are the methods .getPosition(int x, int y) which can be used to confirm that array position is referencing a point, and .getValue(int x, int y) which can be used to confirm that point referenced by that array position has a value to return which is not null.

I am near to tearing my hair out over this exception. Please help.

https://drive.google.com/folderview?id=0B4RWBJX3QmsPZ0g3VnhlSUp6Zk0&usp=sharing

1 Answer

David Eskin
David Eskin
754 Points

A user on Reddit helped me figure out what the exact problem was. In the loop I used to initialize the array of points I forgot to reset the y component after the first run through the x component loop, so I only had the last y position for each x position after the first of mGrid (and grid) referencing a Point object,