目前我試圖讀寫futureMeetingArray和pastMeetingArray再後來在getMeetingListOn方法請他們發言。此方法應查找具有相同日期的任何會議並將它們添加到數組並返回該數組。然而,目前它沒有找到這些(到目前爲止,我只在futureMeetingsArray上測試它)。我還包括了addFutureMeeting方法來說明我已經設置瞭如何添加並序列化futureArrayList。每個FutureMeeting對象都有一個全局日曆變量,我通過getter和setter調用它。如果它更清晰,我可以提供此代碼。序列化問題
如果任何人都可以提出一個原因是沒有找到的日期,我將不勝感激。
public class ContactManagerImpl implements ContactManager {
Calendar date;
List<Meeting> futureMeetingArray = new ArrayList<Meeting>();
List<PastMeetingImpl> pastMeetingArray = new ArrayList<PastMeetingImpl>();
List<Contact> allContacts = new ArrayList<Contact>();
@Override
public int addFutureMeeting(Set<Contact> contacts, Calendar date) {
readSerializedData();
int ID = (int)(Math.random()*500 + 1000);
FutureMeetingImpl fm = new FutureMeetingImpl(contacts, ID, date);
futureMeetingArray.add(fm);
makeNewFolder();
try {
FileOutputStream fileOut = new FileOutputStream("./serialized/newfuturemeeting1.out");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(futureMeetingArray); //This is so I can use later methods down where you need to get specific meetings in list form
out.close();
fileOut.close();
}catch(IOException i) {
i.printStackTrace();
}
contactAdder(contacts);
return ID;
}
@Override
public List<Meeting> getMeetingListOn(Calendar date) {
readSerializedData();
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
String formatted = format1.format(date.getTime());
List<Meeting> meetings = new ArrayList<Meeting>();
Meeting currentMeeting = futureMeetingArray.get(0);
if(futureMeetingArray.size() > 0){
for(int x = 0; x < futureMeetingArray.size(); x++){
currentMeeting = futureMeetingArray.get(x);
Calendar currentMeetingsDate = currentMeeting.getDate();
System.out.println("s");
if(currentMeetingsDate == date){
System.out.println("Adding future");
meetings.add(currentMeeting);
}
}
}
for (int p = 0; p < pastMeetingArray.size(); p++){
Meeting currentMeetingPast = new PastMeetingImpl();
SimpleDateFormat format3 = new SimpleDateFormat("yyyy-MM-dd");
String formatted3 = format3.format(currentMeetingPast.getDate());
System.out.println(formatted3);
if(formatted3 == formatted){
System.out.println("Adding future");
meetings.add(currentMeetingPast);
}
}
for(int y = 0; y < meetings.size(); y++){
Meeting meetingPrint = meetings.get(y);
System.out.println("Your list of meetings include meeting IDs: " + meetingPrint.getId());
}
return meetings;
}
}
這可能與序列化問題 - 我可能無法正確使用Calendar類。如果有人有任何關於使用這個信息,我會很感激 – BitLord