Avatar of AndyC1000
AndyC1000
 asked on

Java check not null on double

Dear all,

I'm getting a null pointer exception in the following code block.  I've read I can't check for null if its a double. How do I resolve this?

int sumHotWater = CalculateSumHotWater(hotwater_map);
double hotwater = 0;
if (sumHotWater != 0) {
    hotwater = (applianceTotal.get("Hotwater").doubleValue()); // null pointer exception here
    if (hotwater != 0.0) {
        hotwater /= sumHotWater;
    }
}

Open in new window


Thanks
Java

Avatar of undefined
Last Comment
zzynx

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
zzynx

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Radek Baranowski

check if this:

applianceTotal.get("Hotwater")

yields you anything. what do you expect it to get you ?
SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
zzynx

Thanx 4 axxepting
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck