I'm receiving a null point exception when attempting to write to a file. The error is coming from the line below.
outputWriter.write(animals[p].toString());
Im assuming its because im passing null with the array. The array is previously created and is filled with objects with different values.
Here is my write file:
public void writeAquatic()
{
try
{
BufferedWriter outputWriter;
String fileName = "Output.txt";
outputWriter = new BufferedWriter(new FileWriter(fileName));
for(int p = 0; p < animals.length; p++)
{
outputWriter.write(animals[p].toString());
outputWriter.newLine();
}
outputWriter.flush();
outputWriter.close();
}
catch(IOException ex)
{
System.out.println(ex.getMessage());
}
catch(NullPointerException e)
{
System.out.println("Null Pointer Exception");
}
}