Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2005
    Location
    Indiana (USA)
    Posts
    50
    Thanks
    4
    Thanked 0 Times in 0 Posts

    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();
    
    }

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    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

  • #3
    New Coder
    Join Date
    Mar 2005
    Location
    Indiana (USA)
    Posts
    50
    Thanks
    4
    Thanked 0 Times in 0 Posts
    It is fixed. I got a bit of help elsewhere.

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Please post the solution if you've found one.

  • #5
    New Coder
    Join Date
    Mar 2005
    Location
    Indiana (USA)
    Posts
    50
    Thanks
    4
    Thanked 0 Times in 0 Posts
    win was still set to null in the AbstractGame class


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •