title: Why is this call to JList.clearSelection() giving me a null pointer exception?
body: <p>this is the first time that I've posted but I tried to follow the guidelines and checked previous questions etc so any help on this would be much appreciated.</p>
  
  <p>I have a JList called history which has a holds a list of strings representing simple mathematical equations (ie 2+2). I want to make it so that when you click on an item in the list it is then concatenated with another string in an input field, all of my methods work when I don't try to clear the selection (so that the same selection can be made multiple times) but when I try to use the clear selection method it throws a null pointer. here's the code where I'm calling it</p>
  
  <pre><code>import javax.swing.JList;
  import javax.swing.ListSelectionModel;
  import javax.swing.event.ListSelectionEvent;
  import javax.swing.event.ListSelectionListener;
  
  public class HistoryListener implements ListSelectionListener {
  
  JList history;
  ListSelectionModel historySelection;
  
  public HistoryListener(JList history) {
      this.history = history;
      historySelection = history.getSelectionModel();
  }
  
  @Override
  public void valueChanged(ListSelectionEvent select) {
  
      if (select.getValueIsAdjusting()) {
          NumListener.addHistory(history.getSelectedValue().toString());
  
      }
  
      if (history.isSelectionEmpty() == false) {
  
          history.clearSelection();
      }
  
  }
  
  }
  </code></pre>
  
  <p>if you need anymore info please let me know</p>
  
  <p>cheers</p>