该方法返回null指针异常,null pinter来自序列化对象,我还无法弄清楚错误

时间:2016-02-25 07:19:02

标签: java arraylist deserialization

此方法属于没有实现可序列化接口的类

   public String FindVetsMedicalAppointments(String id){   MedicalBooking.getInstance().deserializeMedicalBooking();
    for (int i = 0; i < MedicalBooking.mediBookings.size(); i++) {
        MedicalBooking.getInstance().deserializeMedicalBooking();
        if(MedicalBooking.mediBookings.get(i).getVetId().equals(id)){
            System.out.println(MedicalBooking.getInstance().mediBookings.get(i).toString());
        }
    }
    return "END OF APPOINTMENTS";
 }

此方法位于实现可序列化接口的类

  public void deserializeMedicalBooking(){
    try{
            FileInputStream fileIn = new FileInputStream("Medical Appointments.txt");
    ObjectInputStream in = new ObjectInputStream(fileIn);
    mediBookings = (ArrayList<MedicalBooking>) in.readObject();
    } catch (ClassNotFoundException | IOException i) {}
}

0 个答案:

没有答案