title: Exception in "main"java.lang.NullPointerException:Cannot invoke "java.lang.Integer.intValue()"the return value of "java.util.Map.get(Object)" is null
body: <p>I'm having trouble with this code. I copied this code from the book.. What is the problem??</p>
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class WordCount {
      // minimum number of occurrences needed to be printed
  
      public static final int OCCURRENCES = 2000;
  
      public static void main(String[] args) throws FileNotFoundException {
          System.out.println(&quot;This program displays the most&quot;);
          System.out.println(&quot;frequently occurring words from&quot;);
          System.out.println(&quot;the book Moby Dick.&quot;);
          System.out.println();
  
          // read the book into a map
          Scanner in = new Scanner(new File(&quot;moby.txt&quot;));
          Map&lt;String, Integer&gt; wordCountMap = getCountMap(in);
  
          for (String word : wordCountMap.keySet()) {
              int count = wordCountMap.get(word);
              if (count &gt; OCCURRENCES) {
                  System.out.println(word + &quot; occurs &quot; + count + &quot; times.&quot;);
              }
          }
      }
  
      // Reads book text and returns a map from words to counts.
      public static Map&lt;String, Integer&gt; getCountMap(Scanner in) {
          Map&lt;String, Integer&gt; wordCountMap = new TreeMap&lt;String, Integer&gt;();
  
          while (in.hasNext()) {
              String word = in.next().toLowerCase();
              if (wordCountMap.containsKey(word)) {
                  // never seen this word before
                  wordCountMap.put(word, 1);
              } else {
                  // seen this word before; increment count
                  int count = wordCountMap.get(word);
                  wordCountMap.put(word, count + 1);
              }
          }
  
          return wordCountMap;
      }
  }
  </code></pre>