I'm having some trouble deserializing a file that I previously created by serializing, everything is working fine until this point...I can't figure out what I'm doing wrong...
This is the method so far ``` //deserialize from file created by serializeToDisk public static ArrayList<Fruit> fromSerialized( String fileInput, ArrayList<Fruit> newFruitDetails) { FileInputStream fis; try { fis = new FileInputStream(fileInput); ObjectInputStream ois = new ObjectInputStream(fis); newFruitDetails = (ArrayList<Fruit>) ois.readObject(); ois.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return newFruitDetails; }
Just guessing what could be wrong, maybe class Fruit or superclasses don't implement Serializable, or .ser file extensions aren't being used, or something else. On a side note, it's missing a `fis.close();`
What is or isn't happening with this code?
The superclass, Grocery, implements Serializable so I didn't make the fruit class implement Serializable. The file being deserialized wasn't a .ser file. I fixed that. I added the `fis.close();` but an arrayList still isn't being made.
okay, my bad method is working, I just wasn't calling the displayFruits() method right, so I couldn't see the results Thanks
Good to hear
Join our real-time social learning platform and learn together with your friends!