• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creepy NullPointerException  RSS feed

 
Johannes Thorén
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm making a little program, and i cant get rid of a nullpointerexception. I'm trying to make a list of inherited classes plus
some implemented classes. The implemented classes works but the inherited dont. I cant really see whats wrong. Thankful for your help.

Kind regards, Johannes

Here are the methods and classes that doesint work:
First the error log:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at controller.Controller.createEmployes(Controller.java:61)
at view.View.actionPerformed(View.java:130)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2012)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2335)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:404)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:253)
at java.awt.Component.processMouseEvent(Component.java:6108)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:5873)
at java.awt.Container.processEvent(Container.java:2105)
at java.awt.Component.dispatchEventImpl(Component.java:4469)
at java.awt.Container.dispatchEventImpl(Container.java:2163)
at java.awt.Component.dispatchEvent(Component.java:4295)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4461)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4125)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4055)
at java.awt.Container.dispatchEventImpl(Container.java:2149)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4295)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:604)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)


at view.View.actionPerformed(View.java:130):



at controller.Controller.createEmployes(Controller.java:61):


Staff class:




Employe class:



Manager class:


Shopassistant class:
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which one is line 61? Are any of the objects used in that method actually null?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Johannes Thorén wrote:
at controller.Controller.createEmployes(Controller.java:61):

Which is line 61 in your source code? That'll tell you which the null pointer is. It's either going to be toCreate, staff, or store - probably one of the last two.
 
Johannes Thorén
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
staff.createManager(); is line 61.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case it looks like you haven't created a staff object.
 
Johannes Thorén
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought so too, but i have, here is the whole controller class:

 
Johannes Thorén
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just saw my own fault, i havint initialized it..
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell me why you're creating a new StoreAnimals in 3 different places? And not just initialize it when the constructor runs and after that just use it. Looks weird to me.
 
Johannes Thorén
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know hehe, probably i just made one of the method, and then just put it everywhere to make it work.

Thanks for the help everyone
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Johannes Thorén wrote: . . . i just made one of the method, and then just put it everywhere to make it work. . . .
Beware: "I just made one . . ." is a very effective way to write code which doesn't work
 
Johannes Thorén
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah i know, but sometimes its just so frustrating when nothing works, and you cant find the problem, so eventually you just start putting stuff here and there
and then all of a sudden everything works perfectly. And then i'm like "NOW I CANT TOUCH ANYTHING!!!"
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!