Alright so I have to Save and Load an array, and I am unfortunately running into issues at saving, where it keeps giving me the error
Exception in thread "main" java.lang.NullPointerException
at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
at java.io.FileOutputStream.<init>(FileOutputStream.java:84)
at SocialEventList.saveAppointmentData(SocialEventList.java:41)
at Test.main(Test.java:120)
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
public class SocialEventList {
private SocialEvent[] thelist = new SocialEvent[10];
private int i = 0;
private int counter = 0;
private String save;
public void add(SocialEvent se){
if(i<thelist.length){
thelist[i]=se;
++i;
System.out.println(thelist[i]);
}
}
public void display(){
for(int j = 0; j < i; j++){
System.out.println(thelist[j].toString(i));
}
}
public void occursOn(int month, int day, int year) {
for(int h = 0; h<i;h++)
{
if( month==thelist[h].getMonth()&&day==thelist[h].getDay() &&year==thelist[h].getYear() ) {
System.out.println("You have event "+h+ " that occurs on the same day, check to make sure you have enough time.");
display();
}
else{
System.out.println("This event "+h+ " are no two events occur on this same day");
}
}
}
public void saveAppointmentData(){
for(int k = 0; k<i;k++){
PrintStream out = null;
try {
out = new PrintStream(new FileOutputStream(save));
out.println(thelist[k]);
}
catch(FileNotFoundException e){
System.out.println("Error opening the file ");
System.exit(0);
}
}
}
}
else if(input.equals("SAVE")){
sel.saveAppointmentData();
}