For some reason this object cannot be serialized, it used to work but when I use the constructor with the arraylist it started to through error, and now the problem is that when serializing a, there's also an error...
This is the constructor:
private double cost;
private char InputType, CurrencyType;
int Year, Month, Day, MonthlyTotal;
ArrayList<FinanceDailyRecord> setDailyRecord;
public FinanceDailyRecord(double cost, char InputType, char CurrencyType, int Year, int Month, int Day) {
this.cost = cost;
this.InputType = InputType;
this.CurrencyType = CurrencyType;
this.Year = Year;
this.Month = Month;
this.Day = Day;
}
public FinanceDailyRecord(int Day, ArrayList<FinanceDailyRecord> setDailyRecord) {
this.Day = Day;
this.setDailyRecord = setDailyRecord;
}
This is the serialization part
ArrayList<FinanceDailyRecord> RecordArray = new ArrayList<>();
FinanceDailyRecord dailyRecord = new FinanceDailyRecord(22,RecordArray);
System.out.println(dailyRecord);
FinanceDailyRecord a = new FinanceDailyRecord(9.0, 'a','a',12,1,212);
FileOutputStream out = new FileOutputStream("test.bin");
ObjectOutputStream obout = new ObjectOutputStream(out);
obout.writeObject(a);
obout.close();
This is the error:
Exception in thread "main" java.io.NotSerializableException: com.company.FinanceDailyRecord
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at com.company.Main.main(Main.java:23)