Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Null pointerException while calling NotifyObserver (Observer Design pattern)  RSS feed

 
tajinder pal singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

This is what am trying to do.





Above method is being called from





It throws null pointer exception.

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at game.uno.model.UNODeckMain.notifyObservers(UNODeckMain.java:59)
at game.uno.model.UNODeckMain.setThisUnoDeckMain(UNODeckMain.java:38)
at game.uno.controller.UNOGameController.playGame(UNOGameController.java:88)
at game.uno.swings.UnoGui$3.actionPerformed(UnoGui.java:144)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)




Am trying to bring the ObjectInfo(on change) from UNODeckMain into GUI




Code snippet of class where am registering Observer




Let me know if i need to provide any other info.

Thanks.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is line 59 in UNODeckMain? Which object is null? Possibly "ob".
 
tajinder pal singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ulfdittmer , yes ob is null.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you have some list or array or other collection of Observer references, and one of them is null. If that was intentional then you'll need some code to skip those null entries in the loop you posted. But most likely it wasn't intentional, so you should look at the code which builds the list/array/collection and find out why it's inserting null references.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!