My code is similar to the following:
public class A {
private HashMap<Character, Boolean> myMap;
public A() {
myMap = new HashMap<Character, Boolean>();
String mychars = "asdfzxcvqwer";
for (char c : mychars.toCharArray())
myMap.put(c, true);
}
public void doo(String input) {
StringBuilder output = new StringBuilder();
for (char c : input.toCharArray()) {
if (myMap.get(c))
output.append(c);
}
}
//...
//...
}
Why am I getting a null pointer exception (NPE) at the line if (myMap.get(c))
?