Hi I am having an error running this code
Map<String, Integer> map = new TreeMap<String, Integer>();//Already populated
public ArrayList<Map<String, Integer>> storage(){
for (String getCharacter : map.keySet()){
String convertBinGrp;
**Integer binGroups = Integer.valueOf(getCharacter);**
if ( binGroups>=0 && binGroups<= 32){
convertBinGrp = Long.toString(binGroups);
binInsideList.get(convertBinGrp);
Integer getVal = getCharacter.getValue();
binInsideList.put(convertBinGrp, getVal);
}
}
error message: Exception in thread “main” java.lang.NumberFormatException: For input string: ” ”
The error indicated is the Integer binGroups = Integer . valueof(getCharacter) casting.
I’ve already tried using long and double just to make sure its size is bigger because I understand its a String value taken from Map. But is there any other way to solve this? I wanted to convert the String into a numerical value so that I can put it into proper bins or groups. Thanks
Your map contains
" "as one of the keys. The code is trying to interpret the" "as a number, yet it’s not a valid number.You need to figure out where the space is coming from, and then decide on the best course of action (fix the problem that caused it, ignore it, etc).