Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 4.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-23-2008, 04:39 AM   PM User | #1
chiefbutz
New Coder

 
Join Date: Mar 2005
Location: Indiana (USA)
Posts: 50
Thanks: 4
Thanked 0 Times in 0 Posts
chiefbutz is an unknown quantity at this point
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

I am getting a "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" error, and I need some help. I have tried everything I could think of, and it won't fix it.

Code:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at AbstractGame.refreshWindow(AbstractGame.java:20)
	at ChessGame.actionMove(ChessGame.java:293)
	at SquareClick.actionPerformed(SquareClick.java:27)
	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.JToggleButton$ToggleButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Code:
public abstract class AbstractGame {

	public abstract void RunGame(windowControler win);
	protected abstract void display();
	protected abstract boolean tryMove();
	protected abstract boolean clearMovePath(int curY, int curX, int newY, int newX);
	protected abstract void getMoveInfo();
	protected abstract void actionMove();
	
	protected void switchPlayers() {
		if(player == 1)
			player = 2;
		else
			player = 1;
	}
	
	protected void refreshWindow() {
		//try {
			win.refresh(GB.Display(this));
		//}
		//catch(Exception e) {System.out.println("DEBUGGING: Error on window refresh");}
	}
	
	protected int cY = 111, cX = 111, nY = 111, nX = 111; // some stupid number so I know it isn't set
	protected int player = 1; // Defaults to 1
	GameBoard GB;
	boolean CheckMate = false;
	boolean castle = false;
	protected boolean exitGame;
	protected windowControler win;
	boolean hasJumps;
}
actionMove from ChessGame.java
Code:
protected void actionMove() {
		if(tryMove() & !CheckMate) {
			switchPlayers();
		}
		this.refreshWindow();
	}
Code:
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;


public class SquareClick implements ActionListener {

	public SquareClick(AbstractGame game, int x, int y) {
		this.x = x;
		this.y = y;
		myGame = game;
	}
	public void actionPerformed(ActionEvent e) {
		if(myGame.cX == 111 & myGame.cY == 111 & myGame.nX == 111 & myGame.nY == 111) { // Empty values, set initial
			myGame.cX = this.x;
			myGame.cY = this.y;
			//JOptionPane.showOptionDialog(frame, "First cood!", "HELLO!", 
			//		JOptionPane.OK_OPTION,JOptionPane.INFORMATION_MESSAGE, null, null, e);
		}
		else if(myGame.cX != 111 & myGame.cY != 111 & myGame.nX == 111 & myGame.nY == 111) { // set the new location
			myGame.nX = this.x;
			myGame.nY = this.y;
			JOptionPane.showOptionDialog(frame, myGame.cX + " " + myGame.cY + " " + myGame.nX + " " + myGame.nY, "HELLO!", 
					JOptionPane.OK_OPTION,JOptionPane.QUESTION_MESSAGE, null, null, e);
			myGame.actionMove();
			myGame.cX = 111;
			myGame.cY = 111;
			myGame.nX = 111;
			myGame.nX = 111;
			//myGame.refreshWindow();
		}
	}
	protected int x, y;
	AbstractGame myGame;
	Frame frame = new Frame();

}
chiefbutz is offline   Reply With Quote
Old 04-23-2008, 03:50 PM   PM User | #2
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
did u try to print out which of either win or GB is null in your refreshWindow method? it could be as simple as uncommenting the try catch block
__________________
You never have to change anything you got up in the middle of the night to write. -- Saul Bellow
shyam is offline   Reply With Quote
Old 04-23-2008, 03:57 PM   PM User | #3
chiefbutz
New Coder

 
Join Date: Mar 2005
Location: Indiana (USA)
Posts: 50
Thanks: 4
Thanked 0 Times in 0 Posts
chiefbutz is an unknown quantity at this point
It is fixed. I got a bit of help elsewhere.
chiefbutz is offline   Reply With Quote
Old 04-23-2008, 04:41 PM   PM User | #4
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
Please post the solution if you've found one.
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 04-23-2008, 08:18 PM   PM User | #5
chiefbutz
New Coder

 
Join Date: Mar 2005
Location: Indiana (USA)
Posts: 50
Thanks: 4
Thanked 0 Times in 0 Posts
chiefbutz is an unknown quantity at this point
win was still set to null in the AbstractGame class
chiefbutz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:06 PM.


Advertisement
Log in to turn off these ads.