title: Getting Error "Exception in thread "main" java.lang.ExceptionInInitializerError"
body: <p>I am trying to initialize HashMap with Enum Month. However, getting an error like: "Exception in thread "main" java.lang.ExceptionInInitializerError". Please let me know why I am getting this error. I am getting this in static main class method and for line <code>ChatGroups.initializeMap();</code></p>
  
  <pre><code>package static_initialization;
  
  import java.lang.reflect.Type;
  import java.util.HashMap;
  import java.util.Map;
  
  public class ChatGroups {
      public static final Map&lt;String, Month&gt; months = new HashMap&lt;String, Month&gt;() {{
          months.put("Jan", Month.January);
          months.put("Feb", Month.February);
          months.put("Mar", Month.March);
          months.put("Apr", Month.April);
          months.put("Jun", Month.June);
          months.put("Jul", Month.July);
          months.put("Aug", Month.August);
          months.put("Sep", Month.September);
          months.put("Oct", Month.October);
          months.put("Nov", Month.November);
          months.put("Dec", Month.December);
      }};
  
      public static void initializeMap() {
          System.out.println();
      }
  }
  
  
  package static_initialization;
  
  public enum Month {
      January(0),
      February(1),
      March(2),
      April(3),
      May(4),
      June(5),
      July(6),
      August(7),
      September(8),
      October(9),
      November(10),
      December(11);
  
      private int month;
  
      Month(int i) {
          month = i;
      }
  }
  
  
  package static_initialization;
  
  public class Main {
      public static void main(String[] args) {
          initializeMaps();
      }
      public static void initializeMaps() {
  
          try {
              ChatGroups.initializeMap();
          } catch (Exception ex) {
              System.out.println("Neelabh exception = " + ex);
          }
      }
  }
  </code></pre>
  
  <p>Please find the stack trace</p>
  
  <pre><code>Exception in thread "main" java.lang.ExceptionInInitializerError
      at static_initialization.Main.initializeMaps(Main.java:10)
      at static_initialization.Main.main(Main.java:5)
  Caused by: java.lang.NullPointerException
      at static_initialization.ChatGroups$1.&lt;init&gt;(ChatGroups.java:9)
      at static_initialization.ChatGroups.&lt;clinit&gt;(ChatGroups.java:8)
  </code></pre>