So below we have the code from the first of my two files, titled Game (keep scrolling down to see the second file + the issue)
public class Game
{
private static final int PLAYING=0;
private static final int RED_WINS=1;
private static final int BLACK_WINS=2;
private static final int DRAW=3;
private static final int RED=4;
private static final int BLACK=5;
private static final int EMPTY=6;
private static final int WALL=7;
private static int board[][];
public Game()
{
int board[][]={{WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL},
{WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL},
{WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL},
{WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL},
{WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL},
{WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL,EMPTY,WALL}};
}
public void draw()
{
for(int r= 0; r< board.length; r++)
{
for(int c= 0; c<board[0].length; c++)
{
if(board[r][c]==WALL)
{
char Wall='|';
board[r][c]=Wall;
}
if(board[r][c]==EMPTY)
{
char Empty=' ';
board[r][c]=Empty;
}
if(board[r][c]==BLACK)
{
char Black='B';
board[r][c]=BLACK;
}
if(board[r][c]==RED)
{
char Red='R';
board[r][c]=RED;
}
System.out.print(board[r][c] + "");
}
System.out.print("\n");
}
}
}
And Below is the code from the second file, MainFile
import java.util.Scanner;
public class MainFile
{
public static void main(String[]args)
{
Game a=new Game();
a.draw();
}
}
When I press compile, the output says Process completed and everything seems fine at first, but when I press run file I get the following runtimerror,could I know what I'm doing wrong and how can I fix it?
Exception in thread "main" java.lang.NullPointerException
at Game.draw(Game.java:28)
at MainFile.main(MainFile.java:7)