I was working with XML parsing.Since I am learning it just now it would be good if somebody helps me to find the errors in my code
This is the code snippet:
I have declared all the variables correctly...
.....
.....
try { myURL = new URL(fao_addr); } catch (MalformedURLException e) { System.out.println(e); e.printStackTrace(); } try { feed = xmlReader.read(fao_addr); } catch (DocumentException e) { System.out.println(e); e.printStackTrace(); } String xpathExpression = "/Data/FAO"; nodes = feed.selectNodes(xpathExpression); String xpathExpression2 = "/Data/FAO/region/hasMember"; List<? extends Node> subnodes = feed.selectNodes(xpathExpression2); System.out.println("The FAO Members by region in "+language+ " language are : "); for (Node node : nodes) { Node region = node.selectSingleNode("region"); System.out.println(region.getText()); for(Node subnode : subnodes) { String acc_variable="nameShort"+language; Node short_name = subnode.selectSingleNode(acc_variable); System.out.println(short_name.getText()+"\n"); //Error Here.. } }
This is the XML file I am trying to access
http://www.fao.org/countryprofiles/g...FAOByRegion/EN
This is the error I get in the mentioned line
Exception in thread "main" java.lang.NullPointerException
Thanks in advance