java - Created method, having trouble returning a variable in it -
In this method, an XML file is read and some information about it is put in a list. Everything is working for all codes / other methods, I am having trouble returning the "list" variable.
package ca3; Import java.io.file; Import java.util.ArrayList; Import java.util.LinkedList; Import java.util.list; Import org.w3c.dom.Document; Import org.w3c.dom. *; Import javax.xml.parsers.DocumentBuilderFactory; Import javax.xml.parsers.DocumentBuilder; Import org.xml.sax.SAXException; Import org.xml.sax.SAXParseException; Public class xmlReader {public string filename; Public xmlReader (string file log) {fileName = fileLoca; } Public list list; Public list return list (string file n) {Mp3 list woww = null; String fName; String lName; Mp3Lister qwewq; Try {DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance (); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder (); Document doctor = docbuilder.parse (new file (fileN)); // normalize the text presentation doc.getDocumentElement () .normalize (); System.out.println ("The root element of the document" + doc.getDocumentElement (). GetNodeName ()); Nodlist listoffersphone = doc.getElementsByTagName ("person"); Int totalPersons = listOfPersons.getLength (); System.out.println ("Total Number of People:" + Total Promotions); List list = new linked list (); // Duplex linked list (int s = 0; s
I think the local variable that you declare in the return list function. Are you coming back true In the square variable, which is also called list , the reason is that the local list variable is in reference to your return statement (local list variable , out of context until the time of the try, try) block you have declared) If you want to return the value to the local list variable then replace the first line of return list : return to public list list ( String file n) {mp3Lister woww = null; string fName; string lName; Mp3List qwewq; list list = new linked list (); Try { ) and then delete the declaration of the list variable inside the try block.
Comments
Post a Comment