Note that there are some explanatory texts on larger screens.

plurals
  1. POcan't remove first element from jcombobox
    primarykey
    data
    text
    <p>I cannot remove the first element from jcombobox. my code is as follows,</p> <pre><code>JComboBox cBox= cBox= new JComboBox(); ... while (cBox.getItemCount() &gt; 0) cBox.removeItemAt(0); </code></pre> <p>For a test run, i had 3 items in the cBox. When it gets to removeItemAt(0), the debug goes haywire going in to some File access code which is absolutely not related. Does this twice then gets the below exception. I tried removeAllItems() which directly gets the same exception. However, removeItem(1) works as it should until theres only 1 element left. The exception doesn't crash the app and i can see no items in the combobox after so it worked a little. What exactly am i doing wrong.</p> <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at util.Gui$4.actionPerformed(Gui.java:111) at javax.swing.JComboBox.fireActionEvent(Unknown Source) at javax.swing.JComboBox.contentsChanged(Unknown Source) at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source) at javax.swing.DefaultComboBoxModel.setSelectedItem(Unknown Source) at javax.swing.DefaultComboBoxModel.removeElementAt(Unknown Source) at javax.swing.JComboBox.removeItemAt(Unknown Source) at util.Gui.prepareSubLists(Gui.java:164) at util.Gui$3.actionPerformed(Gui.java:97) at javax.swing.JComboBox.fireActionEvent(Unknown Source) at javax.swing.JComboBox.setSelectedItem(Unknown Source) at javax.swing.JComboBox.setSelectedIndex(Unknown Source) at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(Unknown Source) at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload