Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get values from rows in a bigdecimal variable and at the same time want to keep totalling. I used the following code but get NULL POINTER exception like: .myapplication.reportOnTodaysExpenses}: java.lang.NullPointerException.

public static BigDecimal gg = null;

gg= gg.add(new BigDecimal(c.getString(3)));
Posted

You get a NullPointerException because you try to call the add function on gg when it's still null. First give gg a value, then call the add function. For example:
Java
public static BigDecimal gg = new BigDecimal(0);
 
Share this answer
 
You failed to initialize gg. I would use the very fact that zero is the neutral value of addition:
Java
BigDecimal gg = new BigDecimal(0);
gg = gg.add(new BigDecimal("10.5611111111111111111111111111111111111111111111119"));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900