• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

nullpointerexceptions, can anybody help?

 
Lisa Tostrams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
I need to make sort of a bouncing ball game, in a MVC setting. The controller and view part were supplied, i need to write the model. I have some exceptions i cant figure out, and i hope someone can help me.

Here are the errors, i will post the code in the next post:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at vogels.model.VogelModel.getVogels(VogelModel.java:14)
at vogels.controller.Controller.afbeelden(Controller.java:32)
at vogels.view.View.componentResized(View.java:118)
at java.awt.Component.processComponentEvent(Component.java:6215)
at java.awt.Component.processEvent(Component.java:6169)
at java.awt.Container.processEvent(Container.java:2045)
at java.awt.Window.processEvent(Window.java:1876)
at java.awt.Component.dispatchEventImpl(Component.java:4750)
at java.awt.Container.dispatchEventImpl(Container.java:2103)
at java.awt.Window.dispatchEventImpl(Window.java:2518)
at java.awt.Component.dispatchEvent(Component.java:4576)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:672)
at java.awt.EventQueue.access$400(EventQueue.java:96)
at java.awt.EventQueue$2.run(EventQueue.java:631)
at java.awt.EventQueue$2.run(EventQueue.java:629)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:116)
at java.awt.EventQueue$3.run(EventQueue.java:645)
at java.awt.EventQueue$3.run(EventQueue.java:643)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:642)
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)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at vogels.model.VogelModel.update(VogelModel.java:36)
at vogels.controller.Controller.update(Controller.java:23)
at vogels.view.View$3.actionPerformed(View.java:95)
at javax.swing.Timer.fireActionPerformed(Timer.java:313)
at javax.swing.Timer$DoPostEvent.run(Timer.java:244)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:670)
at java.awt.EventQueue.access$400(EventQueue.java:96)
at java.awt.EventQueue$2.run(EventQueue.java:631)
at java.awt.EventQueue$2.run(EventQueue.java:629)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:640)
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)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at vogels.model.VogelModel.getVogels(VogelModel.java:14)
at vogels.controller.Controller.afbeelden(Controller.java:32)
at vogels.view.View.componentResized(View.java:118)
at java.awt.Component.processComponentEvent(Component.java:6215)
at java.awt.Component.processEvent(Component.java:6169)
at java.awt.Container.processEvent(Container.java:2045)
at java.awt.Window.processEvent(Window.java:1876)
at java.awt.Component.dispatchEventImpl(Component.java:4750)
at java.awt.Container.dispatchEventImpl(Container.java:2103)
at java.awt.Window.dispatchEventImpl(Window.java:2518)
at java.awt.Component.dispatchEvent(Component.java:4576)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:672)
at java.awt.EventQueue.access$400(EventQueue.java:96)
at java.awt.EventQueue$2.run(EventQueue.java:631)
at java.awt.EventQueue$2.run(EventQueue.java:629)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:116)
at java.awt.EventQueue$3.run(EventQueue.java:645)
at java.awt.EventQueue$3.run(EventQueue.java:643)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:642)
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)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at vogels.model.VogelModel.getVogels(VogelModel.java:14)
at vogels.controller.Controller.afbeelden(Controller.java:32)
at vogels.view.View.componentResized(View.java:118)
at java.awt.AWTEventMulticaster.componentResized(AWTEventMulticaster.java:159)
at java.awt.Component.processComponentEvent(Component.java:6215)
at java.awt.Component.processEvent(Component.java:6169)
at java.awt.Container.processEvent(Container.java:2045)
at java.awt.Window.processEvent(Window.java:1876)
at java.awt.Component.dispatchEventImpl(Component.java:4750)
at java.awt.Container.dispatchEventImpl(Container.java:2103)
at java.awt.Window.dispatchEventImpl(Window.java:2518)
at java.awt.Component.dispatchEvent(Component.java:4576)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:672)
at java.awt.EventQueue.access$400(EventQueue.java:96)
at java.awt.EventQueue$2.run(EventQueue.java:631)
at java.awt.EventQueue$2.run(EventQueue.java:629)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:116)
at java.awt.EventQueue$3.run(EventQueue.java:645)
at java.awt.EventQueue$3.run(EventQueue.java:643)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:642)
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)
 
Lisa Tostrams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator





 
Rob Camick
Ranch Hand
Posts: 2600
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
at vogels.model.VogelModel.getVogels(VogelModel.java:14)


The problem is at line 14 in your VogelModel class. You have a null variable. Determine which variable is null and then fix the problem.
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lisa. Welcome to the Ranch!

To add to what Rob said: if the code you posted has the same line numbers as in the real files, there's only one possible cause for a null-pointer exception on line 14 - the vogel variable. Make sure that gets initialised before it gets used.
 
Lisa Tostrams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:Hi Lisa. Welcome to the Ranch!

To add to what Rob said: if the code you posted has the same line numbers as in the real files, there's only one possible cause for a null-pointer exception on line 14 - the vogel variable. Make sure that gets initialised before it gets used.


Yeah thats what i figured. But i dont see how its not initialised..
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lisa Tostrams wrote:Yeah thats what i figured. But i dont see how its not initialised..


Well, it looks like it only gets initialised when schietNieuweVogel() is called. I'd suggest initialising it in a constructor to make sure it's always available. But if there's a reason why you can't do that (though I can't see what that would be) then you need to make sure that method gets called first.

So, when you call getVogels() on line 32 of your Controller class, has schietNieuweVogel() been called yet?
 
Lisa Tostrams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:
Lisa Tostrams wrote:Yeah thats what i figured. But i dont see how its not initialised..


Well, it looks like it only gets initialised when schietNieuweVogel() is called. I'd suggest initialising it in a constructor to make sure it's always available. But if there's a reason why you can't do that (though I can't see what that would be) then you need to make sure that method gets called first.

So, when you call getVogels() on line 32 of your Controller class, has schietNieuweVogel() been called yet?


I made a constructor, but now i get another exception.

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1
at vogels.controller.Controller.afbeelden(Controller.java:37)
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lisa Tostrams wrote:I made a constructor, but now i get another exception.

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1
at vogels.controller.Controller.afbeelden(Controller.java:37)

That's in your Controller class again, which we haven't seen, so I've no idea of the specific cause. But it means you're trying to access an array element that doesn't exist. You're looking for element 1, but the array must either be of size 0 or 1 so doesn't have an element 1. And this is happening on line 37, so you should be able to work out which array is the problem. Which is really just what the error message says.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic