CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Java and JSP (http://www.codingforums.com/forumdisplay.php?f=54)
-   -   Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException (http://www.codingforums.com/showthread.php?t=138172)

chiefbutz 04-23-2008 04:39 AM

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

}


shyam 04-23-2008 03:50 PM

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

chiefbutz 04-23-2008 03:57 PM

It is fixed. I got a bit of help elsewhere.

Brandoe85 04-23-2008 04:41 PM

Please post the solution if you've found one.

chiefbutz 04-23-2008 08:18 PM

win was still set to null in the AbstractGame class


All times are GMT +1. The time now is 04:56 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.