问题
Hi i have problem with parsing this xml :
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Items>
<Item>
<TdlID>202</TdlID>
<TdlDesc>1234567890</TdlDesc>
<Due>2013-07-19</Due>
<Done>0</Done>
<Creadate>2013-07-08 23:43:51</Creadate>
<UsrLogin>demouser</UsrLogin>
<Prj>3211</Prj>
<Chngdate>2013-07-17</Chngdate>
</Item>
<Item>
<TdlID>218</TdlID>
<TdlDesc>fghjkljh</TdlDesc>
<Due>2013-07-31</Due>
<Done>1</Done>
<Creadate>2013-07-10 11:06:10</Creadate>
<UsrLogin>demouser</UsrLogin>
<Prj>abcd</Prj>
<Chngdate>2013-07-17</Chngdate>
</Item>
</Items>
<Status>
<code>0</code>
<message>Its Working!!!</message>
</Status>
</Response>
I know, that problem is on 100% in ElementList, but have no idea, where :(
package sk.jbase.todolist.xml;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Order;
import java.util.ArrayList;
import java.util.List;
@Element(name = "Items")
@Order(elements = "Item")
public class Items {
@ElementList(name = "Item")
protected List<Item> item;
public List<Item> getItems() {
if (item == null) {
item = new ArrayList<Item>();
}
return this.item;
}
}
Exception:
07-27 21:44:45.070: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.validate(Composite.java:644)
07-27 21:44:45.075: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readElements(Composite.java:449)
07-27 21:44:45.075: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
07-27 21:44:45.075: E/TEST serializer(16881): org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
07-27 21:44:45.075: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.read(Composite.java:201)
07-27 21:44:45.075: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.read(Composite.java:148)
07-27 21:44:45.075: E/TEST serializer(16881): org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
07-27 21:44:45.075: E/TEST serializer(16881): org.simpleframework.xml.core.CompositeList.populate(CompositeList.java:175)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.CompositeList.read(CompositeList.java:120)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readVariable(Composite.java:623)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readUnion(Composite.java:549)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readElement(Composite.java:532)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readElements(Composite.java:445)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.read(Composite.java:201)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.read(Composite.java:148)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readVariable(Composite.java:623)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readUnion(Composite.java:549)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readElement(Composite.java:532)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readElements(Composite.java:445)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.read(Composite.java:201)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.read(Composite.java:148)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Persister.read(Persister.java:625)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Persister.read(Persister.java:606)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Persister.read(Persister.java:584)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Persister.read(Persister.java:562)
07-27 21:44:45.080: E/TEST serializer(16881): org.simpleframework.xml.core.Persister.read(Persister.java:499)
07-27 21:44:45.080: E/TEST serializer(16881): sk.jbase.myproj.MainActivity$DummySectionFragment$1.dataDownloadedSuccessfully(MainActivity.java:188)
07-27 21:44:45.080: E/TEST serializer(16881): task.RequestTask.onPostExecute(RequestTask.java:98)
07-27 21:44:45.085: E/TEST serializer(16881): task.RequestTask.onPostExecute(RequestTask.java:22)
07-27 21:44:45.085: E/TEST serializer(16881): android.os.AsyncTask.finish(AsyncTask.java:631)
07-27 21:44:45.095: E/TEST serializer(16881): android.os.AsyncTask.access$600(AsyncTask.java:177)
07-27 21:44:45.095: E/TEST serializer(16881): android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
07-27 21:44:45.095: E/TEST serializer(16881): android.os.Handler.dispatchMessage(Handler.java:99)
07-27 21:44:45.095: E/TEST serializer(16881): android.os.Looper.loop(Looper.java:137)
07-27 21:44:45.095: E/TEST serializer(16881): android.app.ActivityThread.main(ActivityThread.java:4898)
07-27 21:44:45.095: E/TEST serializer(16881): java.lang.reflect.Method.invokeNative(Native Method)
07-27 21:44:45.095: E/TEST serializer(16881): java.lang.reflect.Method.invoke(Method.java:511)
07-27 21:44:45.095: E/TEST serializer(16881): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
07-27 21:44:45.095: E/TEST serializer(16881): com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
07-27 21:44:45.095: E/TEST serializer(16881): dalvik.system.NativeStart.main(Native Method)
07-27 21:44:45.885: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.validate(Composite.java:644)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readElements(Composite.java:449)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.read(Composite.java:201)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.read(Composite.java:148)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.CompositeList.populate(CompositeList.java:175)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.CompositeList.read(CompositeList.java:120)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readVariable(Composite.java:623)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readUnion(Composite.java:549)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readElement(Composite.java:532)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readElements(Composite.java:445)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.read(Composite.java:201)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.read(Composite.java:148)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readVariable(Composite.java:623)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readUnion(Composite.java:549)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readElement(Composite.java:532)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.readElements(Composite.java:445)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.read(Composite.java:201)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Composite.read(Composite.java:148)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Persister.read(Persister.java:625)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Persister.read(Persister.java:606)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Persister.read(Persister.java:584)
07-27 21:44:45.890: E/TEST serializer(16881): org.simpleframework.xml.core.Persister.read(Persister.java:562)
07-27 21:44:45.895: E/TEST serializer(16881): org.simpleframework.xml.core.Persister.read(Persister.java:499)
07-27 21:44:45.895: E/TEST serializer(16881): sk.jbase.myproj.MainActivity$DummySectionFragment$1.dataDownloadedSuccessfully(MainActivity.java:188)
07-27 21:44:45.895: E/TEST serializer(16881): task.RequestTask.onPostExecute(RequestTask.java:98)
07-27 21:44:45.895: E/TEST serializer(16881): task.RequestTask.onPostExecute(RequestTask.java:22)
07-27 21:44:45.895: E/TEST serializer(16881): android.os.AsyncTask.finish(AsyncTask.java:631)
07-27 21:44:45.895: E/TEST serializer(16881): android.os.AsyncTask.access$600(AsyncTask.java:177)
07-27 21:44:45.895: E/TEST serializer(16881): android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
07-27 21:44:45.895: E/TEST serializer(16881): android.os.Handler.dispatchMessage(Handler.java:99)
07-27 21:44:45.910: E/TEST serializer(16881): android.os.Looper.loop(Looper.java:137)
07-27 21:44:45.910: E/TEST serializer(16881): android.app.ActivityThread.main(ActivityThread.java:4898)
07-27 21:44:45.910: E/TEST serializer(16881): java.lang.reflect.Method.invokeNative(Native Method)
07-27 21:44:45.910: E/TEST serializer(16881): java.lang.reflect.Method.invoke(Method.java:511)
07-27 21:44:45.910: E/TEST serializer(16881): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
07-27 21:44:45.910: E/TEST serializer(16881): com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
07-27 21:44:45.910: E/TEST serializer(16881): dalvik.system.NativeStart.main(Native Method)
I tried without elementlist, but with one Item element, that working, bud with list no. Can you help me pls?
thanks
回答1:
Solved :
@ElementList(entry = "Item", inline = true)
protected List<Item> item;
来源:https://stackoverflow.com/questions/17901818/simplexml-parsing-elementlist-exception