I'm creating a generic type ArrayQueue and I'm trying to save an ArrayQueue into a text file.
My code:
public void saveToFile(ArrayQueueInterface<Payment> paymentQ){
try {
File file = new File("payment.dat");
ObjectOutputStream ooStream = new ObjectOutputStream(new FileOutputStream(file));
ooStream.writeObject(paymentQ);
ooStream.close();
//this.dispose();
} catch (FileNotFoundException ex) {
System.out.println("ERROR : File not found");
} catch (IOException ex) {
System.out.println("ERROR : Cannot save to file");
}
}
The output showed was: "ERROR: Cannot save to file"
Does anyone have any idea how to fix this?
Here's the full stack trace :
at client.TestPayment.main(TestPayment.java:844)
java.io.NotSerializableException: adt.ArrayQueue
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at entity.PaymentOperation.saveToFile(PaymentOperation.java:337)
at entity.PaymentOperation.addPayment(PaymentOperation.java:72)
at client.TestPayment.init(TestPayment.java:545)
at client.TestPayment.main(TestPayment.java:844)
java.io.NotSerializableException: adt.ArrayQueue
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)