错误来自这一行 BoardState addme = new BoardState();
由于某种原因,它指向的非静态变量是“新的”。我不清楚如何解决这个错误,因为 new 并不是一个变量,也不是。
查看 stackoverflow 记录,此错误通常来自非静态方法,通常通过将方法设为静态或完全绕过该方法来解决。吨
下面的这段代码是为了参考这个语句之前和之后发生的事情。
public class IntelligentTicTacToe extends TicTacToe {
public class BoardState{
public String TTTState;
public int[][] defensiveOppsArray;
public int[][] offensiveOppsArray;
public String str;
public int cnt;
}
public static ArrayList<BoardState> memory = new ArrayList<BoardState>();
public static boolean makeMove(){
char[] oArray = new char[TicTacToeArray.length];
int[][] defensiveOppsArray = new int[TicTacToeArray.length][TicTacToeArray.length];
int[][] offensiveOppsArray = new int[TicTacToeArray.length][TicTacToeArray.length];
int[][] sumOppsArray = new int[TicTacToeArray.length][TicTacToeArray.length];
//converts our Array into a String
String x = convertTTTArrayToString();
//Goes through the conditions to see if we have it in memory or if we must go through all the conditions
boolean matchFound = false;
for(int i=0; i < memory.size(); i++){
BoardState element = memory.get(i);
if(element.str.equals(x)){
System.out.println("Match Found");
matchFound = true;
}}
if(!matchFound){
BoardState addme = new BoardState();
addme.str = x;
addme.cnt = 1;
memory.add(addme);
}
}....