ArrayList<CreatePet> list = null;
public void savePet(String name, String breed, int age, String attribute, int attVal) {
petHolder.add(new CreatePet(name, breed, age, attribute, attVal));
try {
FileOutputStream fileOut = new FileOutputStream("Pet.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(petHolder);
out.close();
fileOut.close();
System.out.println("Data saved in Pet.ser");
} catch (IOException i) {
i.printStackTrace();
}
}
public void openSavedPet() {
try {
FileInputStream fileIn = new FileInputStream("Pet.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
list = (ArrayList) in.readObject();
in.close();
fileIn.close();
for (CreatePet petHolder : list) {
System.out.println(petHolder);
}
} catch(IOException i){
i.printStackTrace();
} catch (ClassNotFoundException c) {
c.printStackTrace();
}
}
Output: "CreatePet@531be3c5" I think this is the memory address.
Here's the CreatePet constructor
public CreatePet(String petName, String breed, int petAge, String attribute, int attVal) {
super(petName, breed, petAge, attribute, attVal);
}
I'm really stumped on this one and I think I'm going in the complete wrong direction. I would greatly appreciate any help.