title: NullPointerException with an ArrayList inside of a HashMap
body: <p>I am attempting to use an arraylist inside of a hashmap to create and iterate counters for different characters fed to the processLine method. I think I have declared all of the variables and the catch statements should handle the cases in which there isn't an entry in the hashmap, but I am still getting a NullPointerException on the <em>curCounts.set(i, 1);</em> line in the second catch statement. I've probably made some dumb mistake, but I can't figure out what it is.</p>
  
  <pre><code>HashMap&lt;Character, ArrayList&lt;Integer&gt;&gt; charCounts;
  
  public DigitCount() { charCounts = new HashMap&lt;&gt;(); }
  
  
  public void processLine (String curLine) {
  
      int length = curLine.length();
      char curChar;
      ArrayList&lt;Integer&gt; curCounts;
      Integer curCount;
  
      for(int i = 0; i &lt; length; i++){
          curChar = curLine.charAt(i);
          try {
              curCounts = charCounts.get(i);
          } catch (NullPointerException ex) {
              curCounts = new ArrayList&lt;&gt;();
          }
  
          try {
              curCount = curCounts.get(i);
              curCount++;
              curCounts.set(i, curCount);
          } catch (NullPointerException ex) {
              curCounts.set(i, 1);
          }
  
          charCounts.put(curChar, curCounts);
      }
  
      linesProcessed++;
      System.out.println("---------------------------" + linesProcessed);
  }
  </code></pre>
  
  <p>Edit: Yes, I did call DigitCount.</p>
  
  <pre><code>public static void main(String args[]) throws Exception
  {
      //creates an instance of the digitCount object and starts the run method
      DigitCount counter = new DigitCount();
      counter.run(args[0]);
  }
  </code></pre>