title: Java: Getting ExceptionInInitializerError for Enums
body: <p>EDIT: Solved but I don't understand why</p>
  
  <p>In PokemonEnum I had this line </p>
  
  <pre><code>private PokemonEnum[ ] pokemon = PokemonEnum.values(); 
  </code></pre>
  
  <p>I changed it to:</p>
  
  <pre><code>private static PokemonEnum[ ] pokemon = PokemonEnum.values(); 
  </code></pre>
  
  <p>and now it works. I never even used that array yet so I don't know why I was getting errors or why static fixed it.</p>
  
  <hr>
  
  <p>I haven't really worked with Enums so I don't really know why I get an ExceptionInInitializerError when I run main (on line 28 when I try to create a new Pokemon). Anyone care to explain please? Thanks.</p>
  
  <pre><code>import java.awt.image.BufferedImage;
  import java.util.ArrayList;
  
  
  public class Pokemon {
  
      private PokemonEnum name;
      private int dexNumber;
      private BufferedImage sprite;
      private TypeEnum[] types = new TypeEnum[1];
      private ArrayList&lt;AbilityEnum&gt; abilities;
      private ArrayList&lt;MoveEnum&gt; moves;
      private short hp;
      private short attack;
      private short defense;
      private short special_attack;
      private short special_defense;
      private short speed;
  
      public Pokemon(PokemonEnum name)
      {
          this.name = name;
          this.dexNumber = name.getDexNum();
      }
  
      public static void main(String[] args)
      {
          Pokemon pikachu = new Pokemon(PokemonEnum.Pikachu);
          System.out.println(pikachu.dexNumber);
      }
  }
  
  
  
     public enum PokemonEnum {
      Pikachu;
  
      public int getDexNum()
      {
          return ordinal()+1;
      }
  
      private PokemonEnum[ ] pokemon = PokemonEnum.values(); 
  }
  
  
  Stack Trace:
  
  Exception in thread "main" java.lang.ExceptionInInitializerError
      at Pokemon.main(Pokemon.java:28)
  Caused by: java.lang.NullPointerException
      at PokemonEnum.values(PokemonEnum.java:1)
      at PokemonEnum.&lt;init&gt;(PokemonEnum.java:722)
      at PokemonEnum.&lt;clinit&gt;(PokemonEnum.java:2)
      ... 1 more
  </code></pre>