Xtream xml转化为bean的问题
xml文件
<QueryRegionByDeviceIdResp>
<resultCode>0</resultCode>
<RegionList>
<Region>
<regionId>340000</regionId>
<regionName>安徽省</regionName>
<regionLevel></regionLevel>
<parentId></parentId>
</Region>
<Region>
<regionId>110000</regionId>
<regionName>北京市</regionName>
<regionLevel></regionLevel>
<parentId></parentId>
</Region>
</RegionList>
</QueryRegionByDeviceIdResp>
三个class类如下
public class QueryRegionByDeviceIdResp {
private String resultCode;
//private List<Region> regionList = new ArrayList<Region>();
private RegionList regionList;
public String getResultCode() {
return resultCode;
}
public void setResultCode(String resultCode) {
this.resultCode = resultCode;
}
public RegionList getRegionList() {
return regionList;
}
public void setRegionList(RegionList regionList) {
this.regionList = regionList;
}
}
public class RegionList {
private List<Region> regionList;
public List<Region> getRegionList() {
return regionList;
}
public void setRegionList(List<Region> regionList) {
this.regionList = regionList;
}
}
public class Region {
private String regionId;
private String regionName;
private String regionLevel;
private String parentId;
public String getRegionId() {
return regionId;
}
public void setRegionId(String regionId) {
this.regionId = regionId;
}
public String getRegionName() {
return regionName;
}
public void setRegionName(String regionName) {
this.regionName = regionName;
}
public String getRegionLevel() {
return regionLevel;
}
public void setRegionLevel(String regionLevel) {
this.regionLevel = regionLevel;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
}
XStream xstream = new XStream();
xstream.alias(
"QueryRegionByDeviceIdResp",
com.XXX.entity.response.QueryRegionByDeviceIdResp.class);
xstream.alias("RegionList", com.XXX.entity.found.RegionList.class);
xstream.alias("Region", com.XXX.entity.found.Region.class);
QueryRegionByDeviceIdResp queryRegionByDeviceIdResp = new QueryRegionByDeviceIdResp();
queryRegionByDeviceIdResp = (QueryRegionByDeviceIdResp) xstream
.fromXML(result);
05-28 08:08:45.618: E/AndroidRuntime(9716): java.lang.RuntimeException: An error occured while executing doInBackground()
05-28 08:08:45.618: E/AndroidRuntime(9716): at android.os.AsyncTask$3.done(AsyncTask.java:299)
05-28 08:08:45.618: E/AndroidRuntime(9716): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
05-28 08:08:45.618: E/AndroidRuntime(9716): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
05-28 08:08:45.618: E/AndroidRuntime(9716): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
05-28 08:08:45.618: E/AndroidRuntime(9716): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
05-28 08:08:45.618: E/AndroidRuntime(9716): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-28 08:08:45.618: E/AndroidRuntime(9716): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
05-28 08:08:45.618: E/AndroidRuntime(9716): at java.lang.Thread.run(Thread.java:856)
05-28 08:08:45.618: E/AndroidRuntime(9716): Caused by: com.thoughtworks.xstream.converters.ConversionException: Element Region of type com.XXX.entity.found.Region is not defined as field in type
com.XXX.entity.found.RegionList
05-28 08:08:45.618: E/AndroidRuntime(9716): ---- Debugging information ----
05-28 08:08:45.618: E/AndroidRuntime(9716): class : com.XXX.entity.found.RegionList
05-28 08:08:45.618: E/AndroidRuntime(9716): required-type : com.XXX.entity.found.RegionList
05-28 08:08:45.618: E/AndroidRuntime(9716): converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
05-28 08:08:45.618: E/AndroidRuntime(9716): path : /QueryRegionByDeviceIdResp/RegionList/Region
05-28 08:08:45.618: E/AndroidRuntime(9716): line number : 10
05-28 08:08:45.618: E/AndroidRuntime(9716): class[1] : com.XXX.entity.response.QueryRegionByDeviceIdResp
05-28 08:08:45.618: E/AndroidRuntime(9716): version : 0.0
05-28 08:08:45.618: E/AndroidRuntime(9716): -------------------------------
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.writeValueToImplicitCollection(AbstractReflectionConverter.java:403)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:334)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:322)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1058)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1042)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.XStream.fromXML(XStream.java:913)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.thoughtworks.xstream.XStream.fromXML(XStream.java:904)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.XXX.activity.RegionActivity$QueryRegionByDeviceId.doInBackground(RegionActivity.java:105)
05-28 08:08:45.618: E/AndroidRuntime(9716): at com.XXX.activity.RegionActivity$QueryRegionByDeviceId.doInBackground(RegionActivity.java:1)
05-28 08:08:45.618: E/AndroidRuntime(9716): at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-28 08:08:45.618: E/AndroidRuntime(9716): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
05-28 08:08:45.618: E/AndroidRuntime(9716): ... 4 more
public class QueryRegionByDeviceIdResp {
private String resultCode;
private List<Region> regionList;
}
public class Region {
}