Forums Register Login
NullPointerException trying to output an array into txt file
Completely stumped. Trying to write on a text file from user inputs. I get a NullPointerException. I'm really stumped because I followed an example from my old work exactly as written. Only difference is that I'm writing to a text file so maybe syntax or something is not correct. Anyways I hope you can help because at this point I'm completely lost. Here's the code, it's only half the main class so the problem is at the bottom (last for loop):

(1 like)
A couple of administrative points: First, please UseCodeTags (⇐Click). I've added them for you above. Second, when you have an exception, tell us which line it's on.

OK, so your second for loop runs one more iteration than your first, so you try to print out one more pet than you have. And a bonus tip: you don't have to keep putting your Pet object into your array every time you change something. Once it's there, it stays there until replaced with another Pet object (or null), even if its internal values change. I hope that helps!
Ok cool thanks for those tips. And yeah the problem starts at line 54.

And yes thank you! Silly mistake as always...
You're welcome! All mistakes are silly once you spot them. The trick is finding them, but that does get easier with experience.
I just had the craziest dream. This tiny ad was in it.
Thread Boost - a very different sort of advertising

This thread has been viewed 717 times.

All times above are in ranch (not your local) time.
The current ranch time is
Apr 20, 2018 13:53:25.