Two Laptop Bag
The moose likes Beginning Java and the fly likes I don't know what's wrong with this chess game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I don Watch "I don New topic

I don't know what's wrong with this chess game

steve tang

Joined: Jun 12, 2005
Posts: 2
Sorry if the post is inetiquette because this my first time using the forum.
I am making a 2 player chess game using JButtons. The program is supposed to run as the following:

1. create the chessboard with pieces in it

2. select a button

3. determine where the piece could move and count the amount of legal moves and record the positions

4. color these buttons

5. goes to step 2

you click the button to move between 5 and 6

6. according to the amount and the positions~to determine is you click is a legal move or not

you click the button to move between 5 and 6

7. switch the information of the 2 buttons you clicked before

8. fresh~output the result of the switch

9. switch turns

When a piece is clicked on, the possible legal moves are shown but when the square is clicked on, nothing happens. It is supposed to move the piece to the selected square. I think the problem is that the program cannot get to step 2 to move the pieces. Also, when one of the pieces is clicked on, the following error message appears that I don't understand:

Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at Chess.movePawn(
at Chess.actionPerformed(
at javax.swing.AbstractButton.fireActionPerformed(
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
at javax.swing.DefaultButtonModel.setPressed(
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
at java.awt.Component.processMouseEvent(
at javax.swing.JComponent.processMouseEvent(
at java.awt.Component.processEvent(
at java.awt.Container.processEvent(
at java.awt.Component.dispatchEventImpl(
at java.awt.Container.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.LightweightDispatcher.retargetMouseEvent(
at java.awt.LightweightDispatcher.processMouseEvent(

at java.awt.LightweightDispatcher.dispatchEvent(
at java.awt.Container.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.EventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
at java.awt.EventDispatchThread.pumpEvents(

at java.awt.EventDispatchThread.pumpEvents(


The code is:
Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
Hi, and welcome to the Javaranch.

You need to focus on these lines:

at Chess.movePawn(
at Chess.actionPerformed(

Your getting a nullpointer exception - in other words, your trying to call
a method, draw ect. something that isn't initialised. Take a look at line
957,379 and 126 in your Chess class. You might wan't to try to "System.out.println("do I exist in memory? "+ object)" to find out if some of your objects doesn't exist.

Feel free to reply if your still having problems.. but please don't make me read 1000 lines of code
I agree. Here's the link:
subject: I don't know what's wrong with this chess game
It's not a secret anymore!