title: Java Swing JSlider addChangeListener error
body: <p>I am using Swing to make a simple GUI but when I add a change listener to a JSlider, I get the following runtime error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
          at XMovePanel.&lt;init&gt;(XMovePanel.java:15)
  </code></pre>
  
  <p>My code is the following:</p>
  
  <pre><code>public class XMovePanel extends JPanel
  {
      JSlider xCoord;
      private GUIApp d;
      private XMoveListener xmove;
  
      public XMovePanel(GUIApp d)
      {
      this.d = d;
      xmove = new XMoveListener();
  
      // Error occurs here:
      xCoord.addChangeListener(xmove);
  
          // Settings for the slider
    private class XMoveListener implements ChangeListener{
  @Override
          public void stateChanged(ChangeEvent event){
  
          // Change listener does stuff on action here
  </code></pre>
  
  <p>But I don't know why I would get an error when I add the change listener. What am I doing wrong?</p>