Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1084375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:33:14+00:00 2026-05-16T22:33:14+00:00

jComboBox.removeAllItems does not complain until after items are added (it gets called once before

  • 0

jComboBox.removeAllItems does not complain until after items are added (it gets called once before the JComboBox is populated from a configuration file). Stepping through this code I see jComboBox.removeAllItems calls JComboBox.removeAllItems which calls DefaultComboBoxModel.removeAllElements which calls fireIntervalRemoved. There are seven items in jComboBox and the loop in fireIntervalRemoved is executed about four times before throwing the NullPointerException. Any ideas?

public class MyClass extends javax.swing.JFrame {
    ...
    private void updateComboBox() {
        try {
            jComboBox.removeAllItems();
            ...
public class JComboBox ...
    ...
    public void removeAllItems() {
        checkMutableComboBoxModel();
        MutableComboBoxModel model = (MutableComboBoxModel)dataModel;
        int size = model.getSize();
        if ( model instanceof DefaultComboBoxModel ) {
            ((DefaultComboBoxModel)model).removeAllElements();
            ...
public class DefaultComboBoxModel ...
    ...
    public void removeAllElements() {
        if ( objects.size() > 0 ) {
            int firstIndex = 0;
            int lastIndex = objects.size() - 1;
            objects.removeAllElements();
        selectedObject = null;
            fireIntervalRemoved(this, firstIndex, lastIndex);
            ...
public abstract class AbstractListModel ...
    ...
    protected void fireIntervalRemoved(Object source, int index0, int index1)
    {
    Object[] listeners = listenerList.getListenerList();
    ListDataEvent e = null;

    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == ListDataListener.class) {
        if (e == null) {
            e = new ListDataEvent(source, 
                ListDataEvent.INTERVAL_REMOVED, index0, index1);
        }
        ((ListDataListener)listeners[i+1]).intervalRemoved(e);
        ...

java.lang.NullPointerException

at abc.MyClass.jComboBoxActionPerformed(MyClass.java:211)
at abc.MyClass.access$000(MyClass.java:16)
at abc.MyClass$1.actionPerformed(MyClass.java:110)
at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1240)
at javax.swing.JComboBox.contentsChanged(JComboBox.java:1311)
at javax.swing.JComboBox.intervalRemoved(JComboBox.java:1331)
at javax.swing.AbstractListModel.fireIntervalRemoved(AbstractListModel.java:161)
at javax.swing.DefaultComboBoxModel.removeAllElements(DefaultComboBoxModel.java:169)
at javax.swing.JComboBox.removeAllItems(JComboBox.java:751)
at abc.MyClass.updateComboBox(MyClass.java:58)
at abc.MyClass.jMenuItemDevicesDeleteActionPerformed(MyClass.java:231)
at abc.MyClass.access$300(MyClass.java:16)
at abc.MyClass$4.actionPerformed(MyClass.java:154)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1223)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1264)
at java.awt.Component.processMouseEvent(Component.java:6267)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:33:14+00:00Added an answer on May 16, 2026 at 10:33 pm

    It’s not throwing an NPE. Your code is.

    java.lang.NullPointerException
    at abc.MyClass.jComboBoxActionPerformed(MyClass.java:211)
    at abc.MyClass.access$000(MyClass.java:16)
    at abc.MyClass$1.actionPerformed(MyClass.java:110)
    ...
    

    Look at MyClass.java, line 211.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am saving items to JComboBox from a textfield(input) when a button is clicked.
Does the method JComboBox.removeAllItems() in turn fire an ItemStateChanged event..? If so, how do
I have a JComboBox with many items. I added an item listener to this
I have a JComboBox and have 10 string items added in it. I want
How do I use JComboBox (strict or non-strict) from swingx ? Can somebody post
I would like to make a JComboBox that has check boxes for items instead
I have a JComboBox on my Panel. One of the popup menu items is
HI, I have a JComboBox to which I'm adding my custom object items. But
I have 2 JComboBox components added to my GUI productComboBox and categoryComboBox , with
I would like to populate a java.swing JComboBox with values from an Enum .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.