- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试对已编码的 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 必须称为 getLes 或 isLes ( boolean 值)。因此:
public void setLes(Les lessen) { ... }
关于java - JAXB 解码返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36295144/
我正在考虑使用 JAXB 进行 XML 解析,但到目前为止我遇到了一些问题,这让我相信它可能不够灵活,无法满足我的需求。 我将解析第三方提供的 XML 以符合我将发布的 XSD。所以我想足够灵活地处理
我正在考虑使用 JAXB 进行 XML 解析,但到目前为止我遇到了一些问题,这让我相信它可能不够灵活,无法满足我的需求。 我将解析第三方提供的 XML 以符合我将发布的 XSD。所以我想足够灵活地处理
我有一个 xsd,用于使用 JAXB 在 Java 中生成对象模型,并且我希望将它生成的列表重命名为 xyzList 而不是 xyz。有没有办法做到这一点,而不必在绑定(bind)文件中为每个列表添加
我们正在使用 JAXB 构建许多开发人员应用程序,并不断遇到问题,这些问题都归结为 JAXB 对象的生产者和消费者之间的“版本”不匹配。 过程并没有减轻痛苦,所以我正在考虑一些类似于 JAXB 的 C
我们有一个在一个属性上带有 JAXB 注释的类。然后我们有几个子类来注释其余的重要数据。然而,我们有一个子类,我们想忽略父类注释,这样它就不会被编码。这是一些示例代码。 父类: @XmlType(na
我一直在使用 Oracle JDK 1.7 附带的默认 Sun JAXB 实现。 不幸的是,我有一些非常复杂的 XSD 模式可以使用,而且我发现了 XSD 到 Java 引擎中的一个错误(在 this
我有这个 Maven“任务”来使用 JAXB 从 XSD 文件生成 Java 类。 com.sun.tools.xjc.maven2
我想要这样的 XML: Foo 我可以通过一个看起来像这样的 JAXB 类成功地做到这一点: @XmlRootElement(name="simple") class Simple { @Xm
我有一个 POJO,我想将其编码并作为 xml 发送,但也想解编从同一个 Web 服务返回的数据。但是,此 POJO 中有某些字段,我不想发送,但可能在服务器返回的 xml 中。 这里的问题是,如果我
嘿伙计们,希望这里是一个简单的好东西。 我正在使用 JAXB 从架构生成类,并且我希望能够使用访问者模式来处理它们。 为此,我认为我需要每个 JAXB 生成的类来实现我定义的接口(interface)
我有一个 POJO,我想将其编码并作为 xml 发送,但也想解编从同一个 Web 服务返回的数据。但是,此 POJO 中有某些字段,我不想发送,但可能在服务器返回的 xml 中。 这里的问题是,如果我
这是我的转换代码。当我们处理大数据时,这需要很长时间......调用该方法几乎一百万次......我们可以清楚地看到它持有线程一段时间。 请建议我一些提高性能的方法! public class Gen
我有一个可以成功编码的 jaxb 对象,它有一个列表对象,然后我创建一个如下所示的新对象 public class Sub extends SuperJAXBClass{ @Override publ
我已经将jaxb库更新为2.0版。 我正在使用以下jars jaxb-api-2.0.jar和jaxb-imp-2.0.jar。 现在的问题是,它没有使用@XmlRootElement(name =“
我在使用 JAXB 时面临以下问题:看起来 JAXB 正在分析从最深的子类到父类的属性,并且子属性具有优先级。我想以某种方式改变这种行为。特别是: 子类: package test.sub; impo
我有以下 XML 消息,我需要反序列化它 我该如何处理? 最佳答案 @XmlElements注释用于映射选择结构。 http://b
我们想用 JAX-RS 和 JAXB 实现一个 RESTful-Web 服务。我们有一个使用 xml 的 PUT 方法,如下所示: -1 test test@gmx.de
我有以下代码 @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class SamplePojo { private S
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 2 年前。
所以我有一个 Jersey 的 REST 服务设置。 我的 POJO 被简单地注释为@XmlRootElement 我向我的 REST 服务发送了一个 POST 请求,一切正常。 1- 我向服务发送了
我是一名优秀的程序员,十分优秀!