title: NullPointerException when adding to HashMap
body: <p>I am getting a NullPointerException when adding data to a HashMap. I am writing a class to count the given frequencies of certain Objects. Here is my code (stripped of any unnecessary details):</p>
  
  <pre><code>public class FrequencyCounter {
  
      private Map&lt;Object, Integer&gt; freq;
  
      public FrequencyCounter() {
          freq = new HashMap&lt;Object, Integer&gt;();
      }
  
      public int add(Object key) {        
          System.out.println("Map is null: " + (freq == null));
          System.out.println("Key is null: " + (key == null));
          if (freq.containsKey(key)) {
              return freq.put(key, freq.get(key) + 1);
          }
          return freq.put(key, 1);
      }
  
      public static void main(String[] args) {
          FrequencyCounter fc = new FrequencyCounter();
          fc.add(new Object());
      }
  }
  </code></pre>
  
  <p>The NPE is occuring on the line <code>return freq.put(key, 1);</code> Both println statements print false.</p>
  
  <p>Do any of you know what I may be doing wrong?</p>