 <p>Usually it happens because you have an event associated JComboBox. It is solved if you have control item in the JComboBox to act, for example:</p> <pre><code>jComboBoxExample.addActionListener (new ActionListener () { public void actionPerformed (ActionEvent e) { do_run (); } }); public void do_run() { int n=jComboBoxPerfilDocumentos.getItemCount(); &lt;--THIS IS THE SOLUTION if (n&gt; 0) { String x = jComboBoxPerfilDocumentos.getSelectedItem (). ToString (); } } </code></pre>