Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException on swing

 
Angelo Tan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe this is my first post here in the ranch so let me start this by saying hello to you all!

Alright on topic, the below is supposed to be the main page for a class project i'm currently working on. I actually based the this code on an example from a book i'm reading. But then when i tried expanding it, adding several components, i keep on getting the following error:

Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1045)
at java.awt.Container.add(Container.java:365)
at Panels.<init>(Panels.java:60)
at Panels.main(Panels.java:88)


In addition, the above error is the one i get when i try to run the file (MainPage.java) separately, meaning outside of a project.

But then when i try to run the whole project including the same exact code/file (MainPage.java), once i hit on the Login button (which should setVisible(false) the "Login frame", and then call the MainPage constructor so it will appear on screen) this is what i get instead:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1045)
at java.awt.Container.add(Container.java:365)
at MainPage.<init>(MainPage.java:60)
at LoginFrame.actionPerformed(LoginFrame.java:82)
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.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
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)


How should i go about getting rid of these errors?

 
Stephan van Hulst
Bartender
Pie
Posts: 5812
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks pretty straightforward. You are getting an exception at line 60 in the code you provided. It's a NullPointerException, so chances are, the argument you are passing in line 60 is null.

What could cause such a thing?
 
Angelo Tan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it. Apparently i forgot initialize the exitButton.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic