• Post Reply Bookmark Topic Watch Topic
  • New Topic

Perplexing NullPointerException

 
Shane Kirk
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone encountered this problem before? This happens occasionally (not very often, but once is more often than it should be) and stems from a call to the setVisible() method of my main application JFrame. Any clue as to why this happens sometimes and not others? It's obviously a Swing thread issue, but I haven't been able to figure out why it would get in this state.
java.lang.NullPointerException
at javax.swing.plaf.basic.BasicComboBoxUI.setPopupVisible(BasicComboBoxUI.java:933)
at javax.swing.JComboBox.setPopupVisible(JComboBox.java:789)
at javax.swing.JComboBox.hidePopup(JComboBox.java:782)
at javax.swing.JComboBox$1.ancestorAdded(JComboBox.java:217)
at javax.swing.AncestorNotifier.fireAncestorAdded(AncestorNotifier.java:68)
at javax.swing.AncestorNotifier.propertyChange(AncestorNotifier.java:202)
at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:264)
at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:232)
at javax.swing.JComponent.firePropertyChange(JComponent.java:3801)
at javax.swing.JComponent.addNotify(JComponent.java:4271)
at java.awt.Container.addNotify(Container.java:1859)
at javax.swing.JComponent.addNotify(JComponent.java:4270)
at java.awt.Container.addNotify(Container.java:1859)
at javax.swing.JComponent.addNotify(JComponent.java:4270)
at java.awt.Container.addNotify(Container.java:1859)
at javax.swing.JComponent.addNotify(JComponent.java:4270)
at java.awt.Container.addNotify(Container.java:1859)
at javax.swing.JComponent.addNotify(JComponent.java:4270)
at java.awt.Container.addNotify(Container.java:1859)
at javax.swing.JComponent.addNotify(JComponent.java:4270)
at java.awt.Container.addNotify(Container.java:1859)
at javax.swing.JComponent.addNotify(JComponent.java:4270)
at java.awt.Container.addNotify(Container.java:1859)
at javax.swing.JComponent.addNotify(JComponent.java:4270)
at java.awt.Container.addNotify(Container.java:1859)
at javax.swing.JComponent.addNotify(JComponent.java:4270)
at java.awt.Container.addNotify(Container.java:1859)
at javax.swing.JComponent.addNotify(JComponent.java:4270)
at javax.swing.JRootPane.addNotify(JRootPane.java:658)
at java.awt.Container.addNotify(Container.java:1859)
at java.awt.Window.addNotify(Window.java:395)
at java.awt.Frame.addNotify(Frame.java:479)
at java.awt.Window.show(Window.java:433)
at java.awt.Component.show(Component.java:1128)
at java.awt.Component.setVisible(Component.java:1083)
at com.opone.jdm.JobDatabaseManager.<init>(JobDatabaseManager.java:120)
 
Stu Glassman
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shane, I'm not absolutely certain what this means, but it looks like it has to do with a JComboBox. If you're creating one of those, could you explain how you are using it and possibly post a bit of code showing its usage?
-Stu
 
Shane Kirk
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the funny thing is all JComboBoxes that I use are on another JPanel that's actually added to the main JFrame. But the JPanel that contains the JComboBoxes doesn't even show up in the stack trace....unless it's one of the JComponents being referred to. It's very strange indeed.
My scheme of things is pretty simple. I've got a bunch of JPanels with other components in them. They each have a method called initComponents that are responsible for layout and instantation of child components. initComponents gets called in each constructor. My main application window has it's own initComponents method that lays out each JPanel and finally setVisible(true) is called on the JFrame.
It's your average run of the mill application design. It's almost as if the whole addNotify chain is being executed before my components are properly constructed. But this doesn't make sense to me since all of my components are constructed and layed out prior to setVisible, which starts up this whole mess.
I think I need some Tylenol. :-)
Like I mentioned...this doesn't happened very often. Maybe once out of 20 times the program is fired up. So it's definitely a Swing threading issue of sorts. Maybe I need a crash course in the architecture of the Swing thread model to understand what's going on under the covers.
 
Stu Glassman
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd have to agree. It seems like the components are being told to show before they are completely ready. I'm not absolutely sure how to do this, but maybe you can join the threads so that you don't call setVisible until completely after the components are created.
Hope this helps,
-Stu
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why is JComboBox.setPopupVisible() in the stack trace? is it used for constructing the combobox? I thought it yould be called only when the combo is expanded?
 
Shane Kirk
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it's used whenever it needs to be made visible. Wierd, eh?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!