Lỗi đến từ dòng này BoardState addme = new BoardState();biến không tĩnh này không thể được tham chiếu từ một bối cảnh tĩnh
Vì lý do nào đó, biến không tĩnh mà nó trỏ đến là "mới". Tôi không rõ làm thế nào tôi có thể sửa lỗi này vì mới không có nghĩa là biến, và không phải là.
Nhìn qua các bản ghi lưu lượng ngăn xếp, lỗi này thường xuất phát từ một phương pháp không tĩnh thường được giải quyết bằng cách làm cho phương thức tĩnh hoặc bỏ qua phương thức hoàn toàn. T
Mã dưới đây là để tham khảo những gì đang diễn ra trước và sau tuyên bố này.
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);
}
} ....
bản sao có thể có của [biến không tĩnh không thể được tham chiếu từ ngữ cảnh tĩnh] (http://stackoverflow.com/questions/2559527/non-static-variable-cannot-be-referenced-from-a-static- ngữ cảnh) – EJP