Hello, I am trying to streamline my code to make use of a loop to populate a NameValuePair array. My code compiles..but I get a run-time error:
Exception in thread "main" java.lang.NullPointerException
at lawsonUtil.NVPFromXML(lawsonUtil.java:34)
at WebApplicant.main(WebApplicant.java:72)
code before which compiles and runs fine.....
code after which compiles but does not run....
I am sure it has to do with how I am populating my array..maybe I need to use the "fill" method to populate my array?
Thanks!
Exception in thread "main" java.lang.NullPointerException
at lawsonUtil.NVPFromXML(lawsonUtil.java:34)
at WebApplicant.main(WebApplicant.java:72)
code before which compiles and runs fine.....
Code:
public static NameValuePair[] NVPFromXML(Document indoc)
{
indoc.getDocumentElement().normalize();
NodeList nl = indoc.getElementsByTagName("*");
for (int i=1; i<nl.getLength(); i++)
{
Element elem = (Element) nl.item(i);
System.out.println(elem.getNodeName() + "==>" + elem.getFirstChild().getNodeValue());
}
NameValuePair nvpPdl = new NameValuePair("_PDL","TEST");
NameValuePair nvpTkn = new NameValuePair("_TKN","PA31.1");
NameValuePair nvpRtn = new NameValuePair("_RTN","DATA");
NameValuePair nvpf1 = new NameValuePair("_f1","A");
NameValuePair nvpf10 = new NameValuePair("_f10","3000");
NameValuePair[] nvpout = {nvpPdl, nvpTkn, nvpRtn, nvpf1, nvpf10};
return nvpout;
}
code after which compiles but does not run....
Code:
public static NameValuePair[] NVPFromXML(Document indoc)
{
indoc.getDocumentElement().normalize();
NameValuePair[] nvpOut = null;
NodeList nl = indoc.getElementsByTagName("*");
for (int i=1; i<nl.getLength(); i++)
{
Element elem = (Element) nl.item(i);
System.out.println(elem.getNodeName() + "==>" + elem.getFirstChild().getNodeValue());
nvpOut[i-1] = new NameValuePair(elem.getNodeName(), elem.getFirstChild().getNodeValue()); <===This is the line that fails
}
return nvpOut;
}
I am sure it has to do with how I am populating my array..maybe I need to use the "fill" method to populate my array?
Thanks!