Hello,
i have saved an arrayList to file using the ObjectOutputStream but now when i try to read the file i get problems.
saveOnFile:
public void saveOnFile() { try { ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream("object.txt")); output.writeObject(mediaList); output.close(); } catch(Exception ex) { ex.printStackTrace(); } }
readFromFile:
public void readFromFile() { try { ObjectInputStream inStream = new ObjectInputStream(new FileInputStream("object.txt")); this.mediaList.add( (Media) inStream.readObject()); inStream.close(); } catch(Exception ex) { ex.printStackTrace(); } }
Does it know which instance the object is or do i need to handle this?
ERRORS:
java.lang.ClassCastException: java.util.ArrayList cannot be cast to project.Media at project.MediaHandler.readFromFile(MediaHandler.java:66) at project.Window.<init>(Window.java:73) at project.Window.main(Window.java:199)
ED, my classes are serializable.