THIS IS NOT A DUPLICATE. It looks like it is, on the surface, but the solution for the other problems does not apply.
When I run the following method under Java 1.7, I get a null pointer exception at
normalOutCurrVals.put(new Double(x), new Byte(i));
I have read the documentation and the answers here for closely related problems, but so far I and my team are stumped. Is there something obvious that we are missing?
We simply wish to put in the mappings from double values (that appear on our programs UI) over to their byte counterparts for storage in a simulated device's memory.
Here are the importants declarations:
public final Map<Double, Byte> normalOutCurrVals = mapNormalOutCurrVals();
public final Map<Double, Byte> magnetOutCurrVals = mapMagnetOutCurrVals();
public final Map<Integer, Byte> freqVals = mapFreqVals();
public final Map<String, Byte> onTimeVals = mapOnTimeVals();
public final Map<String, Short> offTimeVals = mapOffTimeVals();
public final Map<String , Short> pulseWidthVals = mapPulseWidthVals();
Any help would be greatly appreciated.
private Map<Double, Byte> mapNormalOutCurrVals(){
Map<Double, Byte> map = new HashMap<Double, Byte>();
double x = 0.000;
byte i = 0;
//first set of normal output currents
while (x <= 2.000){
normalOutCurrVals.put(new Double(x), new Byte(i));
x += 0.125;
i++;
}
while (x <= 4.000){
normalOutCurrVals.put(new Double(x), new Byte(i));
x += 0.250;
i++;
}
while (x <= 8.000){
normalOutCurrVals.put(new Double(x), new Byte(i));
x += 0.500;
i++;
}
return map;
}