I have a program that adds PanelFurniture objects to an ArrayList. When i try to save the data in a file, it is giving me the exception java.io.NotSerializableException: PanelFurniture$1. PanelFurniture is the name of the class, and it implements Serializable already, so I don’t understand what the problem might be.
This is my code for writing the ArrayList to the file
if(ae.getSource() == commandButtons[5]) {
int x = 5 , y = 11;
File confidential = new File("secrets.txt");
PrintWriter output = null;
try {
saveFile = new FileOutputStream("myFile.dat");
save = new ObjectOutputStream(saveFile);
save.writeObject(orderList);
save.close();
System.out.println(orderList);
}
catch (Exception e){
e.printStackTrace();
}
}
}
Your
PanelFurnitureclass, which is the content of yourArrayList, needs to implement theSerializableinterface, as well as any anonymous inner classes (likePanelFurniture$1), so Java doesn’t know how to read/write this data to disk.If you don’t want to use serialization, you are probably wanting to do something like this… (psuedocode)