2016-03-29 20 views
1

Ben marshelled bir XML dosyası unmarshel çalışıyorum, ancak yazdırırken null döndürür.JAXB unmarshelling döndürür null

XML dosyası:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<presentieLijst> 
<les> 
    <begintijd>15:30</begintijd> 
    <docent>John Smeets</docent> 
    <eindtijd>18:00</eindtijd> 
    <lesDatum>2016-02-02</lesDatum> 
    <lesNaam>TCIF-V1AUI-15</lesNaam> 
    <lokaal>D02.08</lokaal> 
</les> 
</presentieLijst> 

XML sarıcı:

package presentie.model; 

import javafx.beans.property.SimpleStringProperty; 
import javafx.beans.property.StringProperty; 

public class Les { 
private final StringProperty lesNaam, 
          lokaal, 
          docent, 
          eindtijd, 
          begintijd, 
          lesDatum; 
//private Klas klas; 

public Les(){this(null,null,null,null,null,null);} 

public Les(String nm, String lok, String doc, String dt, String et, String bt) { 
    this.lesNaam = new SimpleStringProperty(nm); 
    this.lokaal = new SimpleStringProperty(lok); 
    this.docent = new SimpleStringProperty(doc); 
    this.begintijd = new SimpleStringProperty(et); 
    this.eindtijd = new SimpleStringProperty(bt); 
    this.lesDatum = new SimpleStringProperty(dt); 
    //this.klas = kl; 
} 

public StringProperty lesNaamProperty() {return lesNaam;} 
public StringProperty lokaalProperty() {return lokaal;} 
public StringProperty docentProperty() {return docent;} 
public StringProperty begintijdProperty(){return begintijd;} 
public StringProperty eindtijdProperty() {return eindtijd;} 
public StringProperty datumProperty() {return lesDatum;} 

public void setLesNaam(String nm) {this.lesNaam.set(nm);} 
public void setLokaal(String lk) {this.lokaal.set(lk);} 
public void setDocent(String dc) {this.docent.set(dc);} 
public void setBegintijd(String bt){this.begintijd.set(bt);} 
public void setEindtijd(String et) {this.eindtijd.set(et);} 
public void setLesDatum(String dt) {this.lesDatum.set(dt);} 
//public void setKlas(Klas kl) {klas = kl;} 

public String getLesNaam() {return lesNaam.get();} 
public String getLokaal() {return lokaal.get();} 
public String getDocent() {return docent.get();} 
public String getBegintijd() {return begintijd.get();} 
public String getEindtijd() {return eindtijd.get();} 
public String getLesDatum() {return lesDatum.get();} 
//public Klas getKlas() {return klas;} 
} 

unmarshel: ObservableList olarak PresentieLijstWrapper.set takılan alır

@XmlRootElement(name = "presentieLijst") 
public class PresentieLijstWrapper { 
private Les les; 

@XmlElement(name = "les") 
public Les getLes() { 
    return les; 
} 

public void setles(Les lessen) { 
    this.les = lessen; 
} 
} 

"Les" sınıfı işlevi:

public void updateAbsentie(ObservableList<Student> st){ 
    List<File>filesInFolder = null; 
    try { 
     filesInFolder = Files.walk(Paths.get(path+"/data/saves/")) 
       .filter(Files::isRegularFile) 
       .map(Path::toFile) 
       .collect(Collectors.toList()); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    if(filesInFolder.size() != 0){ 
     for(File file : filesInFolder) { 
      if(file.getName().contains(".xml")){ 
       try { 
        JAXBContext context = JAXBContext.newInstance(PresentieLijstWrapper.class); 
        Unmarshaller um = context.createUnmarshaller(); 
        PresentieLijstWrapper wrapper = (PresentieLijstWrapper) um.unmarshal(file); 
        System.out.println(wrapper.getLes()); 
       } catch (JAXBException e) { 
        e.printStackTrace(); 
       } 

      } 
     } 
    } 

Diğer birçok sorulara ve birkaç eğiticiye baktım. öyle burasıdır http://code.makery.ch/library/javafx-8-tutorial/part5/

cevap

0

: Bu ben esas olarak takip ediyorum biridir

public void setles(Les lessen) { ... } 

esastır Java Fasulye kurallarına bağlılık. Bir tesisin saha les çağrılırsa, setter setLes ve alıcı getLes veya boole'ye yönelik Isles çağrılmalıdır. Bu nedenle:

public void setLes(Les lessen) { ... } 
İlgili konular