在android上使用simplexml解析数据时出现值必需异常
我正在使用simplexml解析从网络获取数据。在解析时显示以下错误 错误:在android上使用simplexml解析数据时出现值必需异常,android,simple-framework,Android,Simple Framework,我正在使用simplexml解析从网络获取数据。在解析时显示以下错误 错误: org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=false, name=, required=true, type=void) on field 'jobs' private
org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=false, name=, required=true, type=void) on field 'jobs' private java.util.List com.example.simpledataparsing.JobList.jobs for class com.example.simpledata.line2
<?xml version="1.0" encoding="UTF-8" ?>
<joblist>
<job><id>75027</id><status>OPEN</status><customer>Manikandan</customer><address>asdf</address><city>salem</city><state>tn</state><zip>636005</zip><product>pipe</product><producturl></producturl><comments>asdf</comments></job>
</joblist>
xml文件:
org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=false, name=, required=true, type=void) on field 'jobs' private java.util.List com.example.simpledataparsing.JobList.jobs for class com.example.simpledata.line2
<?xml version="1.0" encoding="UTF-8" ?>
<joblist>
<job><id>75027</id><status>OPEN</status><customer>Manikandan</customer><address>asdf</address><city>salem</city><state>tn</state><zip>636005</zip><product>pipe</product><producturl></producturl><comments>asdf</comments></job>
</joblist>
您必须进行两项更正: 全面推行职业训练 该课程没有完全实施;XML中的字段比实际类中的字段多。这将导致类的反序列化失败 只需将所有这些字段添加到类中并设置适当的注释。请注意,
producturl
标记为@Element(required=false)
,因此不需要任何值,可以为空(如XML中所示)
更正作业列表批注
XML包含一个内联列表,您也必须在类中设置它inline
@Element(name = "joblist")
public class JobList
{
@ElementList(inline = true)
private List<Job> jobs;
// ...
}
@Element(name=“joblist”)
公共类工作清单
{
@ElementList(inline=true)
私人名单工作;
// ...
}
我觉得他建议的解决方案很好您需要为元素指定路径。您是否正在使用DOM解析器??请参阅我仅使用“simplexml”解析来解析数据---->JobList JobList=serializer.read(JobList.class,data,false);
@Element(name = "joblist")
public class JobList
{
@ElementList(inline = true)
private List<Job> jobs;
// ...
}