I have an ArrayList<ItemList>
where ItemList is:
public class ItemList {
public ArrayList<Item> it = new ArrayList<Item>();
public String name = "";
public ItemList() {
}
}
and Item is:
public class Item {
public String name = "";
public int count = 0;
public Item() {
}
}
I try to serialize this list:
try {
FileOutputStream fileOut = new FileOutputStream(sdDir + serFile);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(List_Of_Lists);
out.close();
fileOut.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
I think it's work, becouse I find this file in folder.
But I can't deserialize from file to ArrayList<ItemList>
code:
try {
FileInputStream fileIn = new FileInputStream(sdDir + serFile);
ObjectInputStream in = new ObjectInputStream(fileIn);
List_Of_Lists = (ArrayList<ItemList>) in.readObject();
Log.i("palval", "dir.exists()");
in.close();
fileIn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
How I can deserialize this ArrayList<ItemList>
?
I always catch IOException.
Your Item
and ItemList
classes needs to implements Serializable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With