This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I'm stuck!

 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are my 3 classes:
BarTill.java

Choices.java

When the code runs it should show the ChoicesPanel & depending on what the user chooses a SubChoicesPanel is displayed at the side of the ChoicesPanel. I havwe had the ChoicesPanel working but when I attempted to create the SubChoicesPanel I am getting a NullPointerException.

Starting application C:\Documents and Settings\Dave Johnson\Desktop\BarTill\BarTill.class
java.lang.NullPointerException
at ChoicesPanel.actionPerformed(ChoicesPanel.java:63)
at java.awt.Button.processActionEvent(Button.java:382)
at java.awt.Button.processEvent(Button.java:350)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
Interactive Session Ended
Interactive Session Ended

Please help if you can?
Thanks, Dave.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple really...

That is the corrected code. You passed a null object in your code. You must create the object before you pass it off to another class.
 
bill stinson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after just a quick review you are passing a reference 'b' new BarTill()
to choicesPanel. that instance is never used or initialized. try passing 'this' instead (a reference to the initilized applet)
you may also need to used the swing utilities invokeLater method to add the
panel as well as code to remove the current choices panel and then add the
new one. you might also consider starting with a default choices panel
 
Dave Johnson
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have changed my init() method as suggested i.e:

It still doesn't seem to be right though. Admittedly I am trying this on awful editor (crimson editor) I might wait till I get home later on a better seyup before trying out too much.
If anyone has any other ideas I can try please post?
Thanks, Dave.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!