Ask your own question, for FREE!
Computer Science 18 Online
OpenStudy (javk):

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...

OpenStudy (javk):

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; }

OpenStudy (woodrow73):

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();`

OpenStudy (rsmith6559):

What is or isn't happening with this code?

OpenStudy (javk):

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.

OpenStudy (javk):

okay, my bad method is working, I just wasn't calling the displayFruits() method right, so I couldn't see the results Thanks

OpenStudy (woodrow73):

Good to hear

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!