title: Check If TextField is Equal to an Element in an ArrayList
body: <p>I have the user type in to a TextField in an Applet which I want to check that the String they typed is equal to the corresponding element in the ArrayList of answers, however I get a large compile time error:</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
  at com.game.main.AppletMain.actionPerformed(AppletMain.java:72) // etc
  </code></pre>
  
  <p>Here is the code, Main class (I have edited out unimportant parts:</p>
  
  <pre><code>private TextField commandInput;
  private TextArea messageDisplay;
  private Message messages;
  private Answer answers;
  private int currentLevel;
  
  @Override
  public void actionPerformed(ActionEvent e) {
      String userInput = commandInput.getText();
      if (userInput == answers.getIntroAnswers().get(0)) {
          messageDisplay.append("\n \n" + userInput + "\n \n");
          commandInput.selectAll();
      }
      getCurrentLevel();
  }
  </code></pre>
  
  <p>And here is the Answers class which holds the ArrayList:</p>
  
  <pre><code>package com.game.main;
  
  import java.util.ArrayList;
  
  public class Answer {
  
  private ArrayList&lt;String&gt; introAnswers;
  private String introAns1 = "go", introAns2 = "Go";
  
  public Answer() {
      introAnswers = new ArrayList&lt;String&gt;();
      introAnswers.add(introAns1);
      introAnswers.add(introAns2);
  }
  
  public ArrayList&lt;String&gt; getIntroAnswers() {
      return introAnswers;
  }
  
  }
  </code></pre>