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.
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database

This thread has been viewed 843 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jan 22, 2019 20:08:30.