title: Removing pane causing NullPointerException with java swing
body: <p>I am trying to clear a pane and put a new one in its place with swing. But with my current setup, it throws a NullPointerException that I don't understand. Here is my code:</p>
  
  <pre><code>public static void createAndShowGUI() {
      final JFrame frame = new JFrame("Generator");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      JPanel pane1 = new JPanel();
      JPanel pane2 = new JPanel();
  
      addComponentsToPane(frame.getContentPane(), pane1, pane2);
  
      frame.setLocationRelativeTo(null);
      frame.pack();
      frame.setVisible(true);
  }
  </code></pre>
  
  <p>I have an actionlistener for a button in addComponentsToPane:</p>
  
  <pre><code>    buttonGenerate.addActionListener(new ActionListener(){
          @Override
          public void actionPerformed(ActionEvent evt){
              Map&lt;String,String&gt; replacements = new HashMap&lt;String,String&gt;(10);
              replacements.put("name", textName.getText());
  
              //createTable();
              //makeDocx(replacements);
              removePane();
          }
      });
  </code></pre>
  
  <p>Here is the removePane() function:</p>
  
  <pre><code>    public static void removePane () {
      pane1.removeAll();
  }
  </code></pre>
  
  <p>pane1 has been declared <code>public static JPanel pane1 = null;</code> at the beginning of the class. When i click the button with the actionlistener, it throws <code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException</code> directed at <code>pane1.removeAll();</code>.</p>
  
  <p>Why is this error popping up? I know there is something important i am missing, does anyone know what it is or know of an alternative way to accomplish what I want?</p>
  
  <p>Thanks</p>