I'm new to Java and getting an NullPointerException error with this code at this line:
spielfeld[i][j] = new DominionTile(world,i,j); // last function
Here is the whole program code:
public class MapProvider implements ....... {
private DominionTile[][] spielfeld;
int row;
int col;
public MapProvider(int zahl1, int zahl2) {
DominionTile[][] spielfeld = new DominionTile[zahl1][zahl2];
col = zahl1;
row = zahl2;
}
#Override
public MapTile[] getColumn(int spalte) { // DONE
if ((spalte < 0) && (spalte > col) ) {
return null;
}
else {
return spielfeld[spalte];
}
}
#Override
public int getColumns() { // DONE
return col;
}
#Override
public int getRows() { // DONE
return row;
}
#Override
public boolean isValid(int spalte, int zeile) { // DONE
if ((spalte < 0) && (zeile < 0)) {
return false;
}
else if ((spalte > col) && (zeile > row)) {
return false;
}
else {
return true;
}
}
#Override
public DominionTile getTile(int col, int row) { // DONE
return spielfeld[col][row];
}
#Override
public void setupMapTiles(MapWorld world) { // NICHT FERTIG
final Map karte = world.getMap();
int zeilen = karte.getRows();
int spalten = karte.getColumns();
for (int i = 1; i <= spalten; i++) { // I-TE SPALTE
for (int j = 1; j <= zeilen; j++) { // J-TE ZEILE
spielfeld[i][j] = new DominionTile(world,i,j);
//DominionTile neu = new DominionTile(world, i, j);
//spielfeld[i][j] = (DominionTile)neu;
}
}
}
}
The last function should put a DominionTile in each place of the array. What am I doing wrong?
You have this in your constructor. This declares and assigns to a local variable, not the spielfeld field, and hence the field is left with a null value.
DominionTile[][] spielfeld = new DominionTile[zahl1][zahl2];
You probably want:
public MapProvider(int zahl1, int zahl2) {
spielfeld = new DominionTile[zahl1][zahl2];
col = zahl1;
row = zahl2;
}
i.e. without the type declaration, which will assign to the object's field.
As a starting point, you might want print out the values of zeilen and spalten. I am guessing this is caused by accessing spielfeld[i][j] where spielfeld[i] does not exist in the first place.
Related
I'm currently working on a version of Conway's Game of Life with Netbeans IDE and I wanted to store cells in a matrix. For the operation of going to the Next generation of cells, I would return a new matrix of cells which is calculated from the inputting matrix.
The Code is the following:
public static Cell[][] nextGen(Cell[][] CellList)
{
Cell[][] Copy = CellList.clone();
for (int i = 0; i<Copy.length; i++)
{
for(int n = 0; n<Copy[i].length; n++)
{
if (Copy[i][n].isAlive())
{
if (Cell.count(Copy, i, n) <= 1 || Cell.count(Copy, i, n) >= 4 )
{
CellList[i][n].kill();
}
}else
{
if (Cell.count(Copy, i, n) == 3)
{
CellList[i][n].born();
}
}
}
}
return CellList;
}
The Class is called "Cell"
it has a private boolean property "alive" which can be set to false with the public method kill() or true with the public method born(). Everything except the method for counting alive cells surrounding a specific cell and the method for calculating the new generation is nonstatic.
The Problem why it isn't working is that if I make any changes to the input matrix "CellList", the same thing happens in the copy of this matrix.
How can I let the copy have the same Values but only make changes in the input matrix?
Thanks for the helping!
What you are doing is shallow copy, what you need is deep copy. Try this
public class Cell {
boolean alive = false;
protected Cell clone() {
return new Cell(this);
}
public Cell() {
}
public Cell(Cell cell) {
this.alive = cell.alive;
}
boolean isAlive() {
return alive;
}
void kill() {
alive = false;
}
void born() {
alive = true;
}
static int count(Cell[][] cell, int j, int k) {
return 1;
}
public static void main(String[] args) {
Cell[][] CellList = new Cell[2][3];
CellList[0][1] = new Cell();
nextGen(CellList);
}
public static Cell[][] nextGen(Cell[][] CellList) {
Cell[][] Copy = deepArrayCopy(CellList);
for (int i = 0; i < Copy.length; i++) {
for (int n = 0; n < Copy[i].length; n++) {
if (Copy[i][n].isAlive()) {
if (Cell.count(Copy, i, n) <= 1 || Cell.count(Copy, i, n) >= 4) {
CellList[i][n].kill();
}
} else {
if (Cell.count(Copy, i, n) == 3) {
CellList[i][n].born();
}
}
}
}
return CellList;
}
public static Cell[][] deepArrayCopy(Cell[][] celllist) {
Cell[][] copy = new Cell[celllist.length][celllist[0].length];
for (int i = 0; i < celllist.length; i++) {
for (int k = 0; k < celllist[i].length; k++) {
if (celllist[i][k] != null)
copy[i][k] = celllist[i][k].clone();
}
}
return copy;
}
}
I need to create an ID based on a 15x15 matrix values and since it is not possible to create an integer of size 15, I tried the following reasoning to create an ID of type double:
First I create a String with the values of the cells and while I do this, I look for the cell that has a value of 0. When I find I enter a dot "." in the String. Then I convert my String to BigDecilmal and the method I call doubleValue ().
public double generateId() {
String sid = "";
for (int i = 0; i < this.matrix[0].length; i++) {
for (int j = 0; j < matrix[1].length; j++) {
if (matrix[i][j].equals("0")) {
sid += ".";
} else {
sid += matrix[i][j];
}
}
}
System.out.println("ID: " + new BigDecimal(sid).doubleValue());
return new BigDecimal(sid).doubleValue();
}
I checked and the generated IDs are uniques.
Based on this, I tried to implement HashCode() as follows:
#Override
public int hashCode() {
long bits = doubleToLongBits(id);
int hash = (int) (bits ^ (bits >>> 32));
System.out.println("hash: " + hash);
return hash;
}
But my HashSet continues with duplicate values :(
Does anyone have a suggestion about how to do this?
~~>EDIT
Sate class:
public class State {
public double id;
public String[][] matrix;
public State() {
}
public State(String[][] matrix) {
this.matrix = createMatrix(matrix);//is created from a existing matrix
this.id = generateId();
}
#Override
public boolean equals(Object other) {
if ((other == null) || !(other instanceof State)) {
return false;
}
return ((State) other).getId().equals(this.getId()) && ((State) other).getId() == this.getId();
}
#Override
public int hashCode() {
long bits = doubleToLongBits(id);
int hash = (int) (bits ^ (bits >>> 32));
System.out.println("hash: " + hash);
return hash;
}
public String toString() {
return "Hashcode: " + this.hashCode();
}
public Double getId() {
return id;
}
public void setId(Double id) {
this.id = id;
}
public String[][] getMatrix() {
return matrix;
}
public void setMatrix(String[][] matrix) {
this.matrix = matrix;
}
public double generateId() {
String sid = "";
for (int i = 0; i < this.matrix[0].length; i++) {
for (int j = 0; j < matrix[1].length; j++) {
if (matrix[i][j].equals("0")) {
sid += ".";
} else {
sid += matrix[i][j];
}
}
}
System.out.println("ID: " + new BigDecimal(sid).doubleValue());
return new BigDecimal(sid).doubleValue();
}
private String[][] createMatrix(String[][] matriz) {
String[][] copia = new String[matriz[0].length][matriz[1].length];
for (int i = 0; i < copia[0].length; i++) {
for (int j = 0; j < copia[1].length; j++) {
copia[i][j] = matriz[i][j];
}
}
return copia;
}
your problem is in the equals method,
you have to remove the last part:
&& ((State) other).getId() == this.getId();
you are checking if the Boolean has the same reference, but they don't need the reference to be equal, it's enough that there value is equal
I would propose using the built-in methods of the Arrays class to generate a hashCode and test for equality:
#Override
public int hashCode() {
return Arrays.deepHashCode(matrix);
}
#Override
public boolean equals(Object other) {
if ((other == null) || !(other instanceof State)) {
return false;
}
State s = (State)other;
return Arrays.deepEquals(matrix, s.matrix);
}
I am working on a program that will solve find a path in a maze. The maze is represented by 0's, 1's and an E to represent the Exit. The maze is represented by a 20x30 (0's represent the path, 1's represent walls). I am using a stack to keep track of a previous usable location.
I think I have most of the code figured out, but when I run it and enter the starting position, the final maze doesn't print out.
My code is as follows:
import java.util.*;
import java.io.*;
public class MazeGenerator {
//main
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int userRow, userCol;
MazeGenerator maze = new MazeGenerator();
maze.fillArray();
maze.print();
System.out.println();
//asking for user starting position
System.out.print("What row would you like to start in?: " );
userRow = sc.nextInt();
while(userRow > 29 || userRow < 0) {
System.out.print("INVALID INPUT! PLEASE ENTER VALUES BETWEEN 0 -
29 INCLUSIVE: " );
userRow = sc.nextInt();
}
System.out.println();
System.out.print("What column would you like to start in? ");
userCol = sc.nextInt();
while(userCol > 19 || userCol < 0) {
System.out.print("INVALID INPUT! PLEASE ENTER VALUES BETWEEN 0 -
19 INCLUSIVE: " );
userCol= sc.nextInt();
}
System.out.println("\n\nFind a path using a stack: ");
//maze.userStart(userRow,userCol);
maze.setUserRow(userRow);
maze.setUserColumn(userCol);
maze.solveStack();
//solveStack(maze);
}
//methods for creating maze
public static final int ROW = 30;
public static final int COLUMN = 20;
public int userRow = 0;
public int userColumn = 0;
private static String[][] maze = new String[ROW][COLUMN];
public void fillArray() throws IOException {
File file = new File("maze.txt");
FileReader reader = new FileReader(file);
BufferedReader buff = new BufferedReader(reader);
for(int counter1 = 0; counter1 < ROW; counter1++) {
String l = buff.readLine();
for(int counter2 = 0; counter2 < COLUMN; counter2++) {
maze[counter1][counter2] = String.valueOf(l.charAt(counter2));
}
}
buff.close();
}
public void print() throws IOException {
System.out.printf("%-4s", ""); //spaces column
for (int counter = 0; counter < COLUMN; counter++){
System.out.printf("%-4d",counter); //print the column number
}
System.out.println();
for(int counter1 = 0; counter1 < maze.length; counter1++) { //loop for
printing rows
System.out.printf("%-4d",counter1); //print row number
for(int counter2 = 0; counter2 < maze[counter1].length; counter2++)
{ //loop for printing columns
System.out.printf("%-4s", maze[counter1][counter2]); //printing
values of maze
}
System.out.println(); // new line
}
}
public int getWidth(){
return maze[0].length;
}
public int getHeight(){
return maze.length;
}
public void setUserRow (int userRow) {
this.userRow = userRow;
}
public void setUserColumn (int userColumn) {
this.userColumn = userColumn;
}
public int getUserRow() {
return userRow;
}
public int getUserColumn() {
return userColumn;
}
public String mark(int row, int col, String value) {
assert(inMaze(row,col));
String temp = maze[row][col];
maze[row][col] = value;
return temp;
}
public String mark (MazePosition pos, String value) {
return mark(pos.row(), pos.col(), value);
}
public boolean isMarked(int row, int col) {
assert(inMaze(row,col));
return (maze[row][col].equals("+"));
}
public boolean isMarked(MazePosition pos) {
return isMarked(pos.row(), pos.col());
}
public boolean Clear(int row, int col) {
assert(inMaze(row,col));
return (maze[row+1][col+1] != "1" && maze[row+1][col+1] != "+");
}
public boolean Clear(MazePosition pos) {
return Clear(pos.row(), pos.col());
}
//true if cell is within maze
public boolean inMaze(int row, int col) {
if (row >= 0 && col >= 0 && row < getWidth() && col < getHeight() ) {
return true;
}
return false;
}
//true if cell is within maze
public boolean inMaze(MazePosition pos) {
return inMaze(pos.row(), pos.col());
}
public boolean Done( int row, int col) {
return (maze[row][col].equals("E"));
}
public boolean Done(MazePosition pos) {
return Done(pos.row(), pos.col());
}
public String[][] clone() {
String[][] copy = new String[ROW][COLUMN];
for (int counter1 = 0; counter1 < ROW; counter1++) {
for (int counter2 = 0; counter2 < COLUMN; counter2++) {
copy[counter1][counter2] = maze[counter1][counter2];
}
}
return copy;
}
public void restore(String[][] savedMaze) {
for (int i=0; i< ROW; i++)
for (int j=0; j<COLUMN; j++)
maze[i][j] = savedMaze[i][j];
}
public MazeGenerator clone(MazeGenerator m) {
MazeGenerator maze = new MazeGenerator();
maze = m;
return maze;
}
//**************************************************
//this solution uses a stack to keep track of possible
//states/positions to explore; it marks the maze to remember the
//positions that it's already explored.
public void solveStack() throws IOException {
//save the maze
//MazeGenerator savedMaze = new MazeGenerator();
//savedMaze.clone(m);
String[][] savedMaze = clone();
//declare the locations stack
Stack<MazePosition> candidates = new Stack<MazePosition>();
//insert the start
candidates.push(new MazePosition(userRow,userColumn));
MazePosition current, next;
while (!candidates.empty()) {
//get current position
current = candidates.pop();
if (Done(current)) {
break;
}
//mark the current position
mark(current, "+");
//put its neighbors in the queue
next = current.north();
if (inMaze(next) && Clear(next)) candidates.push(next);
next = current.east();
if (inMaze(next) && Clear(next)) candidates.push(next);
next = current.west();
if (inMaze(next) && Clear(next)) candidates.push(next);
next = current.south();
if (inMaze(next) && Clear(next)) candidates.push(next);
}
if (!candidates.empty()) {
System.out.println("You got it!");
}
else System.out.println("You're stuck in the maze!");
//savedMaze.print();
print();
restore(savedMaze);
}
class MazePosition {
public int row;
public int col;
public MazePosition(int row, int col) {
this.row = row;
this.col = col;
}
public int row() { return row; }
public int col() { return col; }
public void print() {
System.out.println("(" + row + "," + col + ")");
}
//positions
public MazePosition north() {
return new MazePosition(row-1, col);
}
public MazePosition south() {
return new MazePosition(row+1, col);
}
public MazePosition east() {
return new MazePosition(row, col+1);
}
public MazePosition west() {
return new MazePosition(row, col-1);
}
};
}
Without the benefit of a maze.txt, I created one based on your description. Here's what I found...
Short answer:
Your program hits an infinite loop searching for the exit, so it never reaches the code to print it out.
Long answer:
I see 3 problems on 2 lines of code:
1) A simple typo:
if (row >= 0 && col >= 0 && row < getWidth() && col < getHeight() ) {
getHeight() and getWidth() should be swapped:
if (row >= 0 && col >= 0 && row < getHeight() && col < getWidth() ) {
2) In one spot, you're using 1-based indices, when Java uses 0-based indices:
In this line here:
return (maze[row+1][col+1] != "1" && maze[row+1][col+1] != "+");
Array indices in java start at 0. Your row and col variables also start at 0. But you're adding one to them thereby converting them into 1-based indices. So, you'd want:
return (maze[row][col] != "1" && maze[row][col] != "+");
3) You're using != like !equals(), but in Java, == is not the same as .equals()
In the above line of code, you're comparing two Strings with the != operator. But that doesn't work like the String.equals() method, so your Clear() method always returns true.
This is the crux of your stated problem. The search routine, finding every cell clear, works its way into a corner, and then searches the same two adjacent cells forever.
So, what you really want is:
return (!maze[row][col].equals("1") && !maze[row][col].equals("+"));
I am trying to assign a local variable within a for loop an Int value, but the information is contained within a 2D array of cell. I have tried to use parseInt, but it have received the error that parseInt does not work with type cell.
package surroundpack;
import java.awt.*;
import java.util.*;
public class surroundgame {
private Cell [][] board;
private int sizeCol;
private int sizeRow;
private int whoTurn;
private Status status;
private ArrayList<Point> location;
public surroundgame(int size, int start) {
board = new Cell[sizeRow][sizeCol];
sizeRow = size;
sizeCol = size;
status = Status.Running;
whoTurn = start;
board = new Cell[sizeRow][sizeCol];
for (int row = 0; row < sizeRow; row++) {
for (int col = 0; col < sizeCol; col++) {
board[row][col] = Cell.isEmpty;
}
}
}
public Status getGameStatus() {
isWinner();
return status;
}
public int getSizeCol() {
return sizeCol;
}
public void setSizeCol(int sizeCol) {
this.sizeCol = sizeCol;
}
public int getSizeRow() {
return sizeRow;
}
public void setSizeRow(int sizeRow) {
this.sizeRow = sizeRow;
}
public int getWhoTurn() {
return whoTurn;
}
public void setWhoTurn(int whoTurn) {
this.whoTurn = whoTurn;
}
public Cell[][] getBoard() {
return board;
}
public boolean isWinner() {
for (int row = 0; row < this.sizeRow; row++) {
for (int col = 0; col < this.sizeCol; col++) {
Cell num = board[row][col];
// not a winner if this cell is null
if (num != null) {
// Look at above cell
Integer topNum = -1;
if (row > 0) {
board[row-1][col] = Integer.parseInt(board[row][col]);
topNum = board[row-1][col];
if (topNum == null) break;
}
// Look at right cell
Integer rightNum = -1;
if (col == this.sizeCol-1) {
rightNum = board[row][col++];
if (rightNum == null) break;
}
// Look at left cell
Integer leftNum = -1;
if (col == this.sizeCol-1) {
rightNum = board[row][col--];
if (leftNum == null) break;
}
// Look at bottom cell
Integer bottomNum = -1;
if (row > 0) {
topNum = board[row+1][col];
if (topNum == null) break;
}
// do similar for left cell and bottom cell
// Check that topNum is not our current cell
// then check that topNum is the same number as right left and bottom OR those cells are -1, which
// means that side was on an edge.
if (!num.equals(topNum)) {
if ((topNum.equals(rightNum) || rightNum.equals(-1))
&& (topNum.equals(leftNum) || leftNum.equals(-1))
&& (topNum.equals(bottomNum) || bottomNum.equals(-1))) {
return true;
}
}
}
}
}
return false;
}
public void newGame() {
board = new Cell[sizeRow][sizeCol];
status = Status.Running;
for (int row = 0; row < sizeRow; row++) {
for (int col = 0; col < sizeCol; col++) {
board[row][col] = Cell.isEmpty;
}
}
}
public void select (int row, int col) {
if(board[row][col] == Cell.isEmpty) {
if (whoTurn == 0) {
board[row][col] = Cell.Zero;
whoTurn = 1;
}else {
board[row][col] = Cell.One;
whoTurn = 0;
}
}
}
}
This question already has answers here:
What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?
(26 answers)
Closed 5 years ago.
I am working on a program that will solve find a path in a maze. The maze is represented by 0's, 1's and an E to represent the Exit. The maze is represented by a 20x30 (0's represent the path, 1's represent walls). I am using a stack to keep track of a previous usable location.
I think I have most of the code figured out, but whenever i try to run it, i get an ArrayIndexOutOfBoundsException. I think the main problem is that there are no defined walls around the border. Maybe surround the maze with a border of 1's?
My code is as follows:
import java.util.*;
import java.io.*;
public class MazeGenerator {
//main
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int userRow, userCol;
MazeGenerator maze = new MazeGenerator();
maze.fillArray();
maze.print();
System.out.println();
//asking for user starting position
System.out.print("What row would you like to start in?: " );
userRow = sc.nextInt();
while(userRow > 29 || userRow < 0) {
System.out.print("INVALID INPUT! PLEASE ENTER VALUES BETWEEN 0 - 29 INCLUSIVE: " );
userRow = sc.nextInt();
}
System.out.println();
System.out.print("What column would you like to start in? ");
userCol = sc.nextInt();
while(userCol > 19 || userCol < 0) {
System.out.print("INVALID INPUT! PLEASE ENTER VALUES BETWEEN 0 - 19 INCLUSIVE: " );
userCol= sc.nextInt();
}
System.out.println("\n\nFind a path using a stack: ");
//maze.userStart(userRow,userCol);
maze.setUserRow(userRow);
maze.setUserColumn(userCol);
maze.solveStack();
}
//methods for creating maze
public static final int ROW = 30;
public static final int COLUMN = 20;
public int userRow = 0;
public int userColumn = 0;
private static String[][] maze = new String[ROW][COLUMN];
public void fillArray() throws IOException {
File file = new File("maze.txt");
FileReader reader = new FileReader(file);
BufferedReader buff = new BufferedReader(reader);
for(int counter1 = 0; counter1 < ROW; counter1++) {
String l = buff.readLine();
for(int counter2 = 0; counter2 < COLUMN; counter2++) {
maze[counter1][counter2] = String.valueOf(l.charAt(counter2));
}
}
buff.close();
}
public void print() throws IOException {
System.out.printf("%-4s", ""); //spaces column
for (int counter = 0; counter < COLUMN; counter++){
System.out.printf("%-4d",counter); //print the column number
}
System.out.println();
for(int counter1 = 0; counter1 < maze.length; counter1++) { //loop for printing rows
System.out.printf("%-4d",counter1); //print row number
for(int counter2 = 0; counter2 < maze[counter1].length; counter2++) { //loop for printing columns
System.out.printf("%-4s", maze[counter1][counter2]); //printing values of maze
}
System.out.println(); // new line
}
}
public int size() {
return maze.length;
}
public void setUserRow (int userRow) {
this.userRow = userRow;
}
public void setUserColumn (int userColumn) {
this.userColumn = userColumn;
}
public int getUserRow() {
return userRow;
}
public int getUserColumn() {
return userColumn;
}
public String mark(int row, int col, String value) {
assert(inMaze(row,col));
String temp = maze[row][col];
maze[row][col] = value;
return temp;
}
public String mark (MazePosition pos, String value) {
return mark(pos.row(), pos.col(), value);
}
public boolean isMarked(int row, int col) {
assert(inMaze(row,col));
return (maze[row][col].equals("+"));
}
public boolean isMarked(MazePosition pos) {
return isMarked(pos.row(), pos.col());
}
public boolean Clear(int row, int col) {
assert(inMaze(row,col));
return (maze[row][col] != "1" && maze[row][col] != "+");
}
public boolean Clear(MazePosition pos) {
return Clear(pos.row(), pos.col());
}
//true if cell is within maze
public boolean inMaze(int row, int col) {
if (row >= 0 && col<size() && row>= 0 && col<size()) {
return true;
}
else if (row < 0 && col<size() && row >= 0 && col<size()) {
return false;
}
else return false;
}
//true if cell is within maze
public boolean inMaze(MazePosition pos) {
return inMaze(pos.row(), pos.col());
}
public boolean Done( int row, int col) {
return (maze[row][col].equals("E"));
}
public boolean Done(MazePosition pos) {
return Done(pos.row(), pos.col());
}
public String[][] clone() {
String[][] copy = new String[ROW][COLUMN];
for (int counter1 = 0; counter1 < ROW; counter1++) {
for (int counter2 = 0; counter2 < COLUMN; counter2++) {
copy[counter1][counter2] = maze[counter1][counter2];
}
}
return copy;
}
public void solveStack() throws IOException {
//save the maze
String[][] savedMaze = clone();
//declare the locations stack
Stack<MazePosition> candidates = new Stack<MazePosition>();
//insert the start
candidates.push(new MazePosition(userRow,userColumn));
MazePosition current, next;
while (!candidates.empty()) {
//get current position
current = candidates.pop();
if (Done(current)) {
break;
}
//mark the current position
mark(current, "S");
//put its neighbors in the queue
next = current.north();
if (inMaze(next) && Clear(next)) candidates.push(next);
next = current.east();
if (inMaze(next) && Clear(next)) candidates.push(next);
next = current.west();
if (inMaze(next) && Clear(next)) candidates.push(next);
next = current.south();
if (inMaze(next) && Clear(next)) candidates.push(next);
}
if (!candidates.empty())
System.out.println("You got it!");
else System.out.println("You're stuck in the maze!");
print();
}
class MazePosition {
public int row;
public int col;
public MazePosition(int row, int col) {
this.row = row;
this.col = col;
}
public int row() { return row; }
public int col() { return col; }
public void print() {
System.out.println("(" + row + "," + col + ")");
}
//positions
public MazePosition north() {
return new MazePosition(row-1, col);
}
public MazePosition south() {
return new MazePosition(row+1, col);
}
public MazePosition east() {
return new MazePosition(row, col+1);
}
public MazePosition west() {
return new MazePosition(row, col-1);
}
};
}
The error is as follows:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at MazeGenerator.Clear(MazeGenerator.java:137)
at MazeGenerator.Clear(MazeGenerator.java:141)
at MazeGenerator.solveStack(MazeGenerator.java:217)
at MazeGenerator.main(MazeGenerator.java:40)
i think you're doing a mistake in inMaze(int row, int col) method. I'll try to correct it for you
public boolean inMaze(int row, int col) {
if (row >= 0 && col >= 0 && row < getWidth() && col < getHeight() ) {
return true;
}
return false;
}
therefore you have to change the size() method into getWidth() and getHeight()
public int getWidth(){
return maze[0].length;
}
public int getHeight(){
return maze.length;
}