Null Pointer Exception When Retrieving From Hashmap Even Though Containskey() Returns True
I've been developing an Android guitar app, and currently I'm having some problems with HashMap. To sum it up, I get a nullpointer exception when I try to retrieve a value from a H
Solution 1:
It could be you're using "get()" with both indices and string.
Here, you are assuming that indices match up linearly with your table. As your debug shows, they do not. You've set it up to be accessed via Strings, but you're using the index.
for (int i = 0; i < _currentPreset.getCoordiates().size(); i++) {
_currentPreset.setMaxCoordRange(_currentPreset.getParNames().get(i), 0.75f);
}
Here, you are using pareterName, whatever that is. I hope it's a String
if(_currentPreset.getMaxCoordRange().containsKey(pareterName)){
cord.setMaxValueCoord(_currentPreset.getMaxCoordRange(pareterName));
}
For HashMaps to be effective, stick with accessing the data via your String as you've defined it to be:
Post a Comment for "Null Pointer Exception When Retrieving From Hashmap Even Though Containskey() Returns True"