android - Reading XML File with DOM parser crashes after first entry -


I found very useful entries about XML parsing in this forum and then read my XML file with an SD-card Written this code for my Android app unfortunately it is only returning the first value and then crashing.

My XML-file here:

  & lt ;? Xml version = "1.0" encoding = "utf-8" & gt; & Lt; Resources & gt; & Lt; String-array name = "testset" & gt; & Lt; Items & gt; ABCDEFGHIJKLMNOPQRSTUVWXYZ & lt; / Item & gt; & Lt; Items & gt; Abcdefghijklmnopqrstuvwxyz & lt; / Item & gt; & Lt; / String array & gt; & Lt; String-array name = "testetic" & gt; & Lt; Items & gt; ABCDEFGHIJKLMNOPQRSTUVWXYZ & lt; / Item & gt; & Lt; Items & gt; Abcdefghijklmnopqrstuvwxyz & lt; / Item & gt; & Lt; / String array & gt; & Lt; / Resources & gt;  

And this is the parsing part of my code:

  public static list & lt; Testet & gt; Parse (inputstream) {list & lt; Test sets & gt; TsList = null; Documentbuilder Factory Factory = Document Builder. Firmware (); Try {DocumentBuilder builder = factory.newDocumentBuilder (); Document xmlDoc = builder.parse (); Element root = xmlDoc.getDocumentElement (); Nodelist listnode = rootgate elementBitagname (NODE); Testset tracecate = new charger (); (Int i = 0; i & lt; listNodes.getLength (); ++ i) {node curNode = listNodes.item (i); Name of string = ((atri) (Karanod.getAttivities). Item (0))). GetValue (); Testset.setName (name); Node List Listbids = Kornod.GetBillNode (); & Lt; String & gt; Testcases = null; For (int j = 0; j & lt; listChilds.getLength (); ++ j) {node child = list childs.item (j); If (child.getNodeType () == node. ELEMENT_NODE) ​​{string childName = child.getNodeName (); String Child Value = ((Element) child) .getTextContent (); If (childName.equalsIgnoreCase (ITEM)) {log. V (TAG, childValue); Testcases.add (childValue); } Else {Log.v (TAG, "wrong XML format"); }}} Testet.setTestcases (Testcases); TsList.add (testet); is close(); } Hold (pars configuration exception e) {tsList = null; } Catch (SAXException e) {tsList = null; } Hold (IOException e) {tsList = null; } Return tsList; }  

log. V (TAG, childValue);

"post-text" itemprop = "text"> < P> Your problem with this code:

  list & lt; Test sets & gt; TsList = null; & Lt; String & gt; Testcases = null;  

If you do not initialize two lists, you will have to face the NullExceptionError after adding the first child to the testcases list So try to start the code log , and then start your two list except for the exception, such as

  list & lt; Testet & gt; TsList = new ArrayList & lt; Test sets & gt; (); & Lt; String & gt; Testcases = New Arrestists & lt; String & gt; ();  

Feed me back


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -