gpt4 book ai didi

java - JAXB 解码返回 null

转载 作者:太空宇宙 更新时间:2023-11-04 12:46:16 25 4
gpt4 key购买 nike

我正在尝试对已编码的 XML 文件进行解码,但当我打印它时它返回 null。

XML 文件:

<?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 包装器:

@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;
}
}

作为 ObservableList 插入 PresentieLijstWrapper.set 中的“Les”类:

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;}
}

解码函数:

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();
}

}
}
}

我看过许多其他叠加问题和一些教程。这是我主要关注的:http://code.makery.ch/library/javafx-8-tutorial/part5/

最佳答案

这就是它的位置:

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

遵守 Java Bean 约定至关重要。如果属性的字段称为 les,则 setter 必须称为 setLes,而 getter 必须称为 getLesisLes ( boolean 值)。因此:

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

关于java - JAXB 解码返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36295144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com