[jdom-interest] SAXBuilder: Build document from url fails
Matthias Klein
matthias at cmklein.de
Wed Nov 10 20:00:40 PST 2004
I try to use the REST inteface of Amazon.com to perform ItemSearchRequests.
That interface returns a standard XML file containing the results of the
query.
But when I try to build a Document from the result by
Document doc = builder.build(url);
Element root = doc.getRootElement();
Element items = root.getChild("Items");
I keep getting a NullPointerException. (The url represents the target
endpoint of the Amazon Interface and contains the query parameters)
When I save the XML into a file first and do
Document doc = builder.build(file);
Element root = doc.getRootElement();
Element items = root.getChild("Items");
it works fine.
Why can I not build a Document from a url using the SAXBuilder? (Why do I
have to use the detour via a file?)
The only parameter of the SAXBuilder build() method that works here is the
file. When I try any of the other parameters (such as a Reader or
InputStream) I keep getting the NullPointerException below.
The Exception occurs in the last line: Element items =
root.getChild("Items"); Which looks to me as if the data returned by Amazon
did not make it into the Document.
Why is that?
Thanks
Matt
P.S. Here is the exception: (line 107 is the one mentioned above: Element
items = ...)
java.lang.NullPointerException
at AmazonConnector.doItemSearch(AmazonConnector.java:107)
at MidTermProjectMain.main(ProjectMain.java:41)
java.lang.NullPointerException
at AmazonConnector.doItemSearch(AmazonConnector.java:107)
at MidTermProjectMain.main(ProjectMain.java:41)
More information about the jdom-interest
mailing list