r/javahelp • • Apr 29 '16

Why am I getting a null pointer exception and how do I handle it.

I have a test class that I am working on and I am getting a null pointer exception on line 13. I am having trouble handling this exception and I am not sure why. Any ideas? Here is the class I'm working on http://pastebin.com/8EtX2C22. Any little bit of help would be much appreciated.

1 Upvotes

8 comments sorted by

1

u/cheryllium Apr 29 '16

Can you post your other class? (PassengerArrivalFunction)

1

u/[deleted] Apr 29 '16

Here it is. http://pastebin.com/rKGnkHFG . Thank you for looking at it for me.

3

u/cheryllium Apr 29 '16

Your passengerArrivals() function returns null... That would be the source of your null pointer exception.

1

u/[deleted] Apr 29 '16

So I need to throw a null pointer exception in the passenger arrival constructors?

1

u/cheryllium Apr 29 '16

No, you need to return whatever passengerArrivals() is supposed to return (looks like an int[] of some sort), instead of null. (Why does it currently return null?)

1

u/[deleted] Apr 29 '16

I'm not sure why it returns null at the moment I'll look at it. This a group thing that a bunch of us are working on out of a repository.

1

u/Philboyd_Studge Apr 29 '16

It looks like simply an unfinished method stub. Write the actual method.