java - NullPointerException being thrown, but is clearly not null -


I have this method, which gets all the elements of the tag name in a loaded XML document, which is in the form Here's what one of the following is:

MainActivity.java

  ... ArrayList & lt; Nodel & gt; NLists = New Arrestist & lt; Nodel & gt; (); Node list nList = helpergatenodelist (reference gatesset) open ("feed.xml"), "item"); NLists.add (nList); // NullPointerException is being thrown out of this line ...  

Helper.Java

 . .. public static nodelist millennialist (inputstream file, string node name) {dbFactory = DocumentBuilderFactory.newInstance (); Try {dBuilder = dbFactory.newDocumentBuilder (); } Hold (parser configuration exception e) {e.printStackTrace (); } {Document document = try dBuilder.parse (file); Doc.getDocumentElement () Normal () .; Return doc.getElementsByTagName (nodename); } Catch (SAXException e) {e.printStackTrace (); } Hold (IOException e) {e.printStackTrace (); } Return tap; } ...  

feed.xml

  & lt; Data & gt; & Lt; Items & gt; ... & lt; / Item & gt; & Lt; Items & gt; ... & lt; / Item & gt; & Lt; Items & gt; ... & lt; / Item & gt; & Lt; / Data & gt;  

For some reason, main activity is being thrown on the above line, but if I surround that line with a try / catch block and script Continue, everything works fine, and I can use the nodelist without any problem.

So what am I asking, why is the result being clearly not being zero?

Edit:

Okay, I tried to completely destroy ArrayList, and instead of doing this (only for testing):

  string s = helper.jetnodlist (context.getAssets () .open ("feed.xml"), "item"). Item (0) .getNodeName (); Logs. V ("main activity", "" + s);  

and the log output showed the correct node name ("item"). However, an NPE was still thrown on the line where s was defined.

If you have a nullPointerException at

  nLists.add (nList) get; / / NullPointerException is being thrown out of this line  

This means that for some reason nLists is zero, even if the nList would have been zero, one The exception is because the JDK Arrayist allows for the implementation of the list as zero, but if that code block is actually such and you are only starting 2 statements to ArrayList

  ArrayList & lt; NodeList & gt; NLists = New Arrestist & lt; Nodel & gt; ();  

You should probably check again if the exception really happened in that row.

Otherwise there is only possibility that initialization may fail before, because for example no exception or STH found.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -