title: Java HashMap get method null pointer exception
body: <p>My code is similar to the following:</p>
  
  <pre><code>public class A {
          private HashMap&lt;Character, Boolean&gt; myMap;
  
          public A() {
              myMap = new HashMap&lt;Character, Boolean&gt;();
              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);
              }
          }
          //...
          //...
      }
  </code></pre>
  
  <p>Why am I getting a null pointer exception (NPE) at the line <code>if (myMap.get(c))</code>?</p>