title: NullPointerException during executing program with GUI in Java
body: <p>I'm trying to create my first program in Java that uses GUI and I have small problem. I created a window using NetBeans and now I'm createing two more classes - one called GUI that will be controlling my window and of course Main.</p>
  
  <p>Here are codes of both:</p>
  
  <p>GUI:</p>
  
  <pre><code>package client;
  
  import resources.gui.*;
  
  public class GUI {
      public Window window; 
      public GUI(){
          java.awt.EventQueue.invokeLater(new Runnable() {
              public void run() {
                  window=new Window();
                  window.setVisible(true);
              }
          });
      }
      public void Show(){
          window.jTextArea1.setText("Test");
      }
  }
  </code></pre>
  
  <p>Main:</p>
  
  <pre><code>package client;
  
  public class Main {
  
      static GUI gui;
      public static void main(String[] args) {
          gui=new GUI();
          gui.Show();
      }
  }
  </code></pre>
  
  <p>And of course there is one more called Window that extends JFrame.</p>
  
  <p>My problem is that while executing it, there is java.lang.NullPointerException in line that tries to modify jTextArea1. I guess that is because when program is trying to use this function there is no Window class - it hasn't been created yet "thanks to" invokeLater.</p>
  
  <p>If I'm right how can I repair it? There is no way to put that function into run() because in final version it won't be a function - it will be Thread class independent from GUI, that will be created and executed in Main... or at least I would like it to be like that. :)</p>