錯誤來自此行 BoardState addme = new BoardState();非靜態變量不能從靜態上下文中引用
由於某些原因,它指向的非靜態變量是「新」。我不清楚我如何解決這個錯誤,因爲新的並不是一個變量,而不是。
通過stackoverflow記錄來看,這個錯誤通常來自一個非靜態方法,通常通過靜態方法或完全繞過該方法來解決。 T
下面的代碼是引用這個語句之前和之後發生的事情。
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);
}
} ....
可能重複的[非靜態變量不能從靜態上下文引用](http://stackoverflow.com/questions/2559527/non-static-variable-cannot-be-referenced-from-a-static-上下文) – EJP