title: ExceptionInInitializerError that I can't understand
body: <p>This compiles fine:</p>
  <pre><code>static final Screen screen = Screen.getInstance();
  static final InputListener listener = InputListener.getInstance();
  
  static
  {
  
      screen.addListener(listener);
      screen.setCurrentState(new MainMenu());
      screen.setVisible(true);
  }
  
  private GameManager(){
      mobs = new ArrayList&lt;Mobile&gt;();
      player = new Player(100, 100);      
      mobs.add(player);   
  }
  </code></pre>
  <p>This doesn't:</p>
  <pre><code>static final Screen screen = Screen.getInstance();
  static final InputListener listener = InputListener.getInstance();
  
  private GameManager(){
      mobs = new ArrayList&lt;Mobile&gt;();
      player = new Player(100, 100);      
      mobs.add(player);   
      
      screen.addListener(listener);
      screen.setCurrentState(new MainMenu());
      screen.setVisible(true);
  }
  </code></pre>
  <p>Throws: Exception in thread &quot;main&quot; java.lang.ExceptionInInitializerError saying:</p>
  <pre><code>Caused by: java.lang.NullPointerException
  at main.pack.minerdude.GameManager.&lt;init&gt;(GameManager.java:42)
  at main.pack.minerdude.GameManager.&lt;clinit&gt;(GameManager.java:10)
  ... 1 more
  </code></pre>
  <p>Line 10 is:</p>
  <pre><code>private static final GameManager manager = new GameManager();
  </code></pre>
  <p>Line 42 refers to &quot;return manager&quot;:</p>
  <pre><code>public static GameManager getInstance(){
      return manager;
  }
  </code></pre>
  <p>Why is behaving like that if the static block gets generated after creating mob and adding player to it?</p>
  <h2><strong>EDIT</strong></h2>
  <p>So, this is my conclusion after executing this code and getting the following output:</p>
  <pre><code>GameManager constructor
  Screen constructor
  Screen getInstance
  static of GameManager
  GameManager GetInstance
  </code></pre>
  <ol>
  <li><p>Some class wants a GameManager object, so to return it it has to be created first.</p>
  </li>
  <li><p>GameManager has a Screen object declared static and has the same requeriments as the first step.</p>
  </li>
  <li><p>Screen get's created so GameManager has it's static object initialized and continues to initialize the following statics.</p>
  </li>
  <li><p>Now that GameManager it's fully initialized, it returns itself to the first caller.</p>
  </li>
  </ol>
  <p>One would assume that when GameManager getInstnace gets called, before calling it's constructor it would first initialize all it's statics, but it seems it doesn't work that way as the constructors get's called before any of it's statics. If I create a new GameManager directly - not using getInstance() - then the order is preserved: statics, variables, constructor then return.</p>