Hi I have this stack overflow error in Java while running a test to check if my boardSlots are empty.
public class Board {
private BoardSpot a1;
private BoardSpot a2;
private BoardSpot a3;
private BoardSpot b1;
private BoardSpot b2;
private BoardSpot b3;
private BoardSpot c1;
private BoardSpot c2;
private BoardSpot c3;
public Board(){
a1 = new BoardSpot();
a2 = new BoardSpot();
a3 = new BoardSpot();
b1 = new BoardSpot();
b2 = new BoardSpot();
b3 = new BoardSpot();
c1 = new BoardSpot();
c2 = new BoardSpot();
c3 = new BoardSpot();
}
public class BoardSpot extends Board { //Describes a single square in tic tac toe game
private String filledWith;
public BoardSpot() {
this.filledWith = "";
}
I originally had filledWith as type Character and I thought changing it to type String ("") would prevent the error. It did not.
While debugging, the error occurs when public Board() calls new BoardSpot(). Then for some reason public BoardSpot() does not call for this.filledWith = ""; It simply loops back to public Board().
This might be a silly question but I was wondering what caused this issue? I am trying to make a simple tic tac toe game, if you have any recommendations that might make my life easier please do say!