title: java.lang.NumberFormatException: For input string: ""
body: <p>When running this code:</p>
  
  <pre><code>JTextField ansTxt;
  ...
  ansTxt = new JTextField(5);
  String aString = ansTxt.getText();
  int aInt = Integer.parseInt(aString);
  </code></pre>
  
  <p>Why do I get this error?</p>
  
  <blockquote>
    <p>Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""</p>
  </blockquote>
  
  <p>UPDATE:</p>
  
  <pre><code>JTextField ansTxt;
  ansTxt = new JTextField(5);
  
  ansTxt.addKeyListener(new KeyAdapter() {
     public void keyReleased(KeyEvent e) {
      ansTxt = (JTextField) e.getSource();
      String aString = ansTxt.getText().trim();
      int aInt = Integer.parseInt(aString);
     }
  }
  </code></pre>