title: JComboBox returning values
body: <p>What method is used to return the selection chosen by the user?</p>
  
  <pre><code>JPanel ageSelection = new JPanel();
  JLabel age = new JLabel("Age:");
  
  ArrayList&lt;Integer&gt; ageList = new ArrayList&lt;Integer&gt;();
  
  for (int i = 1; i &lt;= 100; ++i) {
      ageList.add(i);
  }
  
  DefaultComboBoxModel&lt;Integer&gt; modelAge = new DefaultComboBoxModel&lt;Integer&gt;();
  for (Integer i : ageList) {
      modelAge.addElement(i);
  }
  
  JComboBox&lt;Integer&gt; ageEntries = new JComboBox&lt;Integer&gt;();
  ageEntries.setModel(modelAge);
  
  ageEntries.addActionListener(new putInTextListener());
  
  ageSelection.add(age);
  ageSelection.add(ageEntries);
  
  
  class putInTextListener implements ActionListener {
      public void actionPerformed (ActionEvent event) {
          ageEntries.getSelectedItem();
      }
  }
  </code></pre>
  
  <p>When the last line is added (<code>ageEntries.getSelectedItem();</code>), I get an error:</p>
  
  <blockquote>
    <p>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException</p>
  </blockquote>
  
  <p>Any ideas?</p>
  
  <p>Edited Code:</p>
  
  <pre><code>class putInAgeListener implements ItemListener {
      public void itemStateChanged(ItemEvent e) {
  
          Object myAge = ageEntries.getSelectedItem();
  
          String myAgeData = myAge.toString();
  
          int i = Integer.parseInt(myAgeData);
  
          System.out.print(i);
  
      }
  }
  </code></pre>