【问题标题】:Element does not have a match in class元素在类中没有匹配项
【发布时间】:2015-04-07 14:19:37
【问题描述】:

我正在使用 Simple XML 框架,刚刚重命名了一些 XML 布局,现在这些布局似乎不再起作用了。

这是我的 XML:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
  <orderListReply id="R000000000006">
    <order orderid="12" type="outbound" state="available">
       <todo>2</todo>
       <done>0</done>
       <lines>1</lines>
       <erporderid>0</erporderid>
    </order>
  </orderListReply>

这是我的代码类定义:

@Root(name="orderListReply")
public class OrderListReplyTelegram extends Telegram {

    @ElementList(name="order", inline=true, required=false)
    private List<OrderListItem> orders;
    ...

这是我得到的错误:

org.simpleframework.xml.core.ElementException:元素“订单”在第 1 行的 nl.minerall.sapphire.pocket.telegrams.OrderListReplyTelegram 类中没有匹配项

【问题讨论】:

    标签: simple-framework


    【解决方案1】:

    不幸的是,调试简单 XML 框架并不容易,但一些试验和错误帮助了我。

    我的OrderListItem 班级有这个标题:

    @Element(name="order")
    public class OrderListItem {
    

    改成这样的时候:

    @Root(name="order")
    public class OrderListItem {
    

    成功了。奇怪的是,在其他代码中,@Element 注释似乎有效(此代码来自另一个正在工作的树)。

    【讨论】:

    • 我注意到注释 @Root 是强制性的。你也可以使用@Root(strict = false)
    猜你喜欢
    • 2018-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-22
    • 2013-04-21
    • 2023-03-11
    • 2019-05-03
    相关资源
    最近更新 更多