I am just beginning java programming. I have got a Null Pointer exception problem in the array List My code is below
ArrayList<Arpaymentitem> arpaymentitemsList= jb.getArpaymentitems();
arpaymentitemsList.removeAll(Collections.singleton(null));
try {
for(Arpaymentitem arpaymentitem:arpaymentitemsList)
{
if (arpaymentitem.getInvoicekey()!=null) {
statement2.setString(1,arpaymentitem.getInvoicekey());
}
if(arpaymentitem.getInvoicekey() != null)
{
statement2.setString(2,arpaymentitem.getAmount());
}
}
statement2.addBatch();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I am getting null pointer exception error in the FOR statement. I am sure there are some null values in the list. To ignore the null values I have introduced a step
ArrayList<Arpaymentitem> arpaymentitemsList= jb.getArpaymentitems();
arpaymentitemsList.removeAll(Collections.singleton(null)); --> remove nulls
The NPE I got is java.lang.NullPointerException at payment.Intacct_Payment.main(Intacct_Payment.java:169) and the line is for(Arpaymentitem arpaymentitem:arpaymentitemsList)
The problem still persists. What am I doing wrong here.