Cześć koledzy i koleżanki. Mam problem z NPE podczas unmarshallingu dokumentu XML.
Klasa modelu:
public class DogModel {
private StringProperty name;
private StringProperty sex;
private StringProperty breed;
private StringProperty coat;
private StringProperty rabiesVaccinations;
private StringProperty otherVaccinations;
private StringProperty litters;
private StringProperty surgicalProcedures;
private StringProperty heats;
private StringProperty birthday;
public DogModel(){
this.name = new SimpleStringProperty(null);
this.sex = new SimpleStringProperty(null);
this.breed = new SimpleStringProperty(null);
this.coat = new SimpleStringProperty(null);
this.rabiesVaccinations = new SimpleStringProperty(null);
this.litters = new SimpleStringProperty(null);
this.surgicalProcedures = new SimpleStringProperty(null);
this.heats = new SimpleStringProperty(null);
this.birthday = new SimpleStringProperty(null);
this.otherVaccinations = new SimpleStringProperty(null);
}
- wygenerowane automatycznie przez IntelliJ gettery i settery
Klasa Wrappera:
@XmlRootElement(name = "dogs")
@XmlAccessorType(XmlAccessType.FIELD)
public class DogCollectionWrapper {
private List<DogModel> dogs;
public List<DogModel> getDogs(){
// if(dogs == null){
// dogs = new ArrayList<DogModel>();
// }
return dogs;
}
public void setDogs(List<DogModel> dogs){
this.dogs = dogs;
}
Metoda obsługująca odczyt z pliku (Zapis działa bez zarzutu):
try {
JAXBContext context = JAXBContext.newInstance(DogCollectionWrapper.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
DogCollectionWrapper wrapper = (DogCollectionWrapper) unmarshaller.unmarshal(file);
dogModelObservableList.clear();
dogModelObservableList.addAll(wrapper.getDogs());
retrieveRabiesVaccinationDates();
retrieveOtherVaccinationDates();
StringUtil stringUtil = new StringUtil();
contentForAlert = stringUtil.alertBuilder(overdueRabiesVaccinationsSet, monthBeforeRabiesVaccinationExpireDateSet, overdueOtherVaccinationsSet,
monthBeforeOtherVaccinationExpireDateSet);
if(!contentForAlert.isEmpty()){
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Informacje");
alert.setHeaderText(null);
alert.setContentText(contentForAlert);
alert.showAndWait();
}
}catch (JAXBException e){
e.printStackTrace();
}
}
Wszystko działało ok do momentu, kiedy implementowałem wrzucanie apki do systemowego traya zamiast zamknięcia, i dodawałem auto zapis na podstawie listenera observable listy. Próbowałem już prawie wszystkiego, co znalazłem na stacku i w innych czeluściach sieci, nic nie działa tak jakbym tego oczekiwał. Jedyne czego jeszcze nie robiłem to zmiany wersji JAXB.
Będę wdzięczny jak ktoś zechce rzucić bardziej doświadczonym okiem ;)