Beginner's trouble: Null Point Exception
Hello! New poster here, I'm trying to code a simplified version of Go. For those of you not familiar with the game, the premise is to surround your opponent's pieces with your own to gain territory. Whosoever has the most territory at the end of the game wins.
Basically, my program creates a frame that has a mouse listener object. When the listener "hears" a click, it will call a batch of methods to add a new stone, determine captured stones, remove captured stone, etc. But while running, the program throws a Null Pointer Exception whenever it tries to add a stone to a board (the board is a 2D array)
Here is the beginning of the code for my frame:
public class GoFrame extends JFrame
{
public GoFrame frame;
public GoFrame()
{
final JFrame frame = new JFrame();
final Goban theBoard = new Goban();
final Game theGame = new Game();
theGame.setGameState(true);
theGame.setCurrentTurn("white");
frame.add(theBoard);
frame.add(theGame);
final BoardComponent boardComp = new BoardComponent();
add(boardComp, BorderLayout.CENTER);
class GoListener implements MouseListener
{
public void mousePressed(MouseEvent event)
{
frame.repaint();
add(boardComp, BorderLayout.CENTER);
int x = event.getX();
int y = event.getY();
x = x/20;
y = y/20;
if (x <= 20 && y <= 20)
{
if (theGame.getGameState() == true)
{
Stone o = new Stone(x, y);
o.setColor(theGame.getTurnColor());
theBoard.addStone(o, x, y);
...
The constructor for the Stone.
public class Stone
{
private String color;
private int[] position;
boolean captured;
public Stone(int x, int y)
{
int[] position = new int[2];
position[0] = x;
position[1] = y;
String color = "colorless";
boolean captured = false;
}
And the main method.
public static void main(String[] args)
{
GoFrame lol = new GoFrame();
lol.setTitle("Go");
lol.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final int FRAME_WIDTH = 410;
final int FRAME_HEIGHT = 435;
lol.setSize(FRAME_WIDTH, FRAME_HEIGHT);
lol.setVisible(true);
}
I'm unsure of whether I initializedtheBoard andtheGame in the right place so I initialized them in theGoFrame, which also contains the listener object, thinking that the listener will have access to them. Apparently, the listener cant find those two objects.
Can anyone help?

