I am trying to make a program that can save data as "data.ser" and retrieve it and output it. However, although it does the task, the program shows that there is an issue with the NullPointerException.
public void loadData(){
ArrayList<Object> deserialized = new ArrayList<Object>();
try {
FileInputStream fileIn = new FileInputStream("data.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
deserialized = (ArrayList<Object>)in.readObject();
in.close();
fileIn.close();
} catch(IOException i ){
i.printStackTrace();
} catch(ClassNotFoundException c){
c.printStackTrace();
} catch(NullPointerException e) {
e.printStackTrace();
}
The message that always pops up when I run the whole program is
Exception in thread "main" java.lang.NullPointerException
at student_Copy.Main.loadData(Main.java:94)
at student_Copy.loadData.main(loadData.java:9)
There is also a class that retrieves the file
public class loadData {
public static void main(String[] args) {
Main main = new Main();
main.loadData();
}