Im writing a method for minesweeper that opens a cell if there is no mine there. If there are no adjacent cells next to mines, it opens the cells around it that do not have mines. I regularly have this error:
Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError This is my source code:
public void open(int row, int col) {
// row = vertical index of the matrix
// col = horizontal index of matrix
unclicked--;
butt[row][col].setEnabled(false); // disable the called button
if (aray[row][col] !=0) // checks if there are no adjacent cells with an adjacent mine count >0
butt[row][col].setText(Integer.toString(aray[row][col]));
else{
if(row < size-1){
open(row+1, col);
if(col<size-1)
open(row+1, col+1);
if(col>0)
open(row+1, col+1);
}
if(row>0){
if(col>0)
open(row-1, col-1);
if(col< size)
open(row-1, col+1);
}
if(col<size-1)
open(row, col+1);
if(col>0)
open(row, col-1);
return;
}
}
Help would be much appreciated