I have created a program that parses an XML file. For simplicity's sake, let's just say that there is only 1 type of child element in the XML file which contains 4 attributes which are doubles (x1, y1, x2, y2) and represent the beginning and ending points of a line. I am using JDOM to parse the XML file. After grabbing each attribute and storing the data in doubles, I create a MyLine object (my own class for storing line data) and try to store the object in a List (java.util.List).
The following code shows this section of my program:
Everything works except of the last line. If I comment it out then I never run into any errors. I even tried using a Vector instead of a List and using addElement instead of add.
I am using MVC to design the program, so the idea behind this is that the Controller calls the Model's parseXML function like this...
... and the parseXML function will return the same
string (url) that was passed in as its parameter if no errors were encountered during the execution of parseXML. If an error is encountered then the string "error" is returned and the else statement above is executed.
Now for the reason I am confused. The only way that the url string that is returned could be changed is if a MalformedURLException, a JDOMException, or an IOException are encountered. So I put System.out.println("error") statements in the catch blocks for each of these exceptions. I ran the program again and "error" was not printed in the console. So then I decided to alter the Controller's code a little to figure out what was going wrong. I changed it so that another String was receiving the returned String from parseXML and then comparing that returned String to the original and writing "true" or "false" to System.out stating whether the Strings matched or not.
This is the code for that:
Strangely enough, still nothing was written to the console. So after realizing that I had added the Controller code to a try block I placed one more System.out call in the catch block for that statement. The code then looked like this...
... I ran the program again and "null" was being printed in the console from the System.out statement in the catch block. What I don't understand is how this excpetion is being thrown. I know that it occurs when I am trying to add a MyLine object to the list in the parseXML function because if I take this line out then it runs fine. Please help!
My project files can be found at this location:
http://filebox.vt.edu/users/glevine/Project1/exception/ My
test file for inputting a url can be found at this location:
http://filebox.vt.edu/users/glevine/Project1/lines.xml