I'm making a mock shopping program, and I need to serialize the store's costs, revenues, and profits from a class (StoreInfo.java) to a file so it can be de-serialized and loaded when the program is restarted and save the values. However, for some reason, the values of my private double variables for costs, revenues, and profits are not being saved.
In my program, there was another class (Inventory.java) I also had to serialize, but its data contained variables of a type that is a class, not a primitive. The serialization worked completely fine in that class, and the method used to serialize is the exact same between Inventory and StoreInfo other than the class names.
Just noting that both of these classes, Inventory and StoreInfo, are singletons.
Here are the variables I want to serialize:
private double totalCosts;
private double totalRevenue;
private double totalProfits;
Here is my code for my methods that serialize and de-serialize the StoreInfo data:
{
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("storeinfo.dat"));
out.writeObject(instance); //instance refers to the one instance of the singleton
out.close();
}
public void load() throws IOException, ClassNotFoundException
{
ObjectInputStream in = new ObjectInputStream(new FileInputStream("storeinfo.dat"));
instance = (StoreInfo) in.readObject(); //instance refers to the one instance of the singleton
in.close();
}