Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Start Button not working  RSS feed

 
mel li
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a start button on my JPanel. But what I am having trouble is starting the game once the user clicks on it. When the user clicks on the start button, the fruit images should start moving. The start button and the game is on the same JPanel. When I clicked the button, a bunch of errors came up.

Here is my code:





The error is:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

at Furutsu7.actionPerformed(Furutsu7.java:110)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)

at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)

at java.awt.Component.processMouseEvent(Component.java:6525)

at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)

at java.awt.Component.processEvent(Component.java:6290)

at java.awt.Container.processEvent(Container.java:2234)

at java.awt.Component.dispatchEventImpl(Component.java:4881)

at java.awt.Container.dispatchEventImpl(Container.java:2292)

at java.awt.Component.dispatchEvent(Component.java:4703)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)

at java.awt.Container.dispatchEventImpl(Container.java:2278)

at java.awt.Window.dispatchEventImpl(Window.java:2750)

at java.awt.Component.dispatchEvent(Component.java:4703)

at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)

at java.awt.EventQueue.access$500(EventQueue.java:97)

at java.awt.EventQueue$3.run(EventQueue.java:709)

at java.awt.EventQueue$3.run(EventQueue.java:703)

at java.security.AccessController.doPrivileged(Native Method)

at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)

at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)

at java.awt.EventQueue$4.run(EventQueue.java:731)

at java.awt.EventQueue$4.run(EventQueue.java:729)

at java.security.AccessController.doPrivileged(Native Method)

at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)

at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.awt.FlowLayout cannot be cast to java.awt.CardLayout
at Furutsu7.actionPerformed(Furutsu7.java:111)


This part of the stack trace says that at line number 111 of your Furutsu7 class, in the actionPerformed method, you attempted to cast something to a CardLayout variable which wasn't a CardLayout.

But there's nothing in your posted code which does anything like that. It doesn't even use the CardLayout type anywhere. So you must have run some other code instead, and it threw this exception.
 
mel li
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.awt.FlowLayout cannot be cast to java.awt.CardLayout
at Furutsu7.actionPerformed(Furutsu7.java:111)


This part of the stack trace says that at line number 111 of your Furutsu7 class, in the actionPerformed method, you attempted to cast something to a CardLayout variable which wasn't a CardLayout.

But there's nothing in your posted code which does anything like that. It doesn't even use the CardLayout type anywhere. So you must have run some other code instead, and it threw this exception.

Oh, sorry. I edited my post.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, problem solved then?
 
mel li
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no, there is still an error. I edited the error on my post.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, is that what you edited? Your post was quite long and you said nothing except that you edited it, so it was impractical for me to go through it all and try to figure out what you had done. So I left the thread for other people to look at.

But anyway you should now know how to read a stack trace and find out which line of code threw an exception. So, which line of code was that?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!