Serialization 序列化问题

Serialization 序列化问题,serialization,calendar,Serialization,Calendar,目前我正在尝试读写futureMeetingArray和pastMeetingArray,然后在getMeetingListOn方法中调用它们。此方法应查找任何具有相同日期的会议,并将其添加到数组中,然后返回该数组。然而,目前还没有找到这些(到目前为止,我只是在未来的会议上测试它)。我还介绍了addFutureMeeting方法,以说明我是如何开始添加futureArrayList并将其序列化的。每个FutureMeting对象都有一个全局日历变量,我通过getter和setter调用它。我可以

目前我正在尝试读写futureMeetingArray和pastMeetingArray,然后在getMeetingListOn方法中调用它们。此方法应查找任何具有相同日期的会议,并将其添加到数组中,然后返回该数组。然而,目前还没有找到这些(到目前为止,我只是在未来的会议上测试它)。我还介绍了addFutureMeeting方法,以说明我是如何开始添加futureArrayList并将其序列化的。每个FutureMeting对象都有一个全局日历变量,我通过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;
    }
}
公共类ContactManagerImpl实现ContactManager{
日历日期;
List futureMeetingArray=new ArrayList();
List pastMeetingArray=new ArrayList();
List allContacts=new ArrayList();
@凌驾
public int AddFutureMeting(设置联系人、日历日期){
读序列化数据();
int ID=(int)(Math.random()*500+1000);
FutureMeetingImpl fm=新的FutureMeetingImpl(联系人、ID、日期);
futureMeetingArray.add(fm);
makeNewFolder();
试一试{
FileOutputStream fileOut=新的FileOutputStream(“./serialized/newfuturemeeting1.out”);
ObjectOutputStream out=新的ObjectOutputStream(fileOut);
out.writeObject(futureMeetingArray);//这样我就可以在需要以列表形式获取特定会议的地方使用后面的方法
out.close();
fileOut.close();
}捕获(IOI异常){
i、 printStackTrace();
}
触点加法器(触点);
返回ID;
}
@凌驾
公共列表getMeetingListOn(日历日期){
读序列化数据();
SimpleDataFormat 1=新的SimpleDataFormat(“yyyy-MM-dd”);
String formatted=format1.format(date.getTime());
列表会议=新建ArrayList();
Meeting currentMeeting=futureMeetingArray.get(0);
if(futureMeetingArray.size()>0){
对于(int x=0;x

我不确定您在这里遇到了什么“序列化”问题。但我看到您使用“==”来比较对象。您应该使用.equals或尝试使用比较器

请参阅这篇文章,了解您不应该使用“==”的原因。

谢谢,我会修改这个。然而,我仍然得到了相同的结果,只是围绕futureMeetingArray循环,没有添加任何内容。我正在使用的测试是:
@test public void testgetMeetingListOn(){System.out.println(“打印日期”+this.DATE);cm.getMeetingListOn(this.DATE);}
添加日期时是否使用相同的日期格式、时区和区域设置(是否传递给addFutureMeeting()的日历实例)如果使用“.equals”进行比较,则比较的两个日期应相同,包括毫秒。如果您不想在比较中包含时间戳,请分别比较年、月和日期。这可能不是序列化的问题-我可能无法正确使用Calendar类。如果有人有任何关于使用这个的信息,我将不胜感激