Take the 2-minute tour ×

The error comes from this line BoardState addme = new BoardState();

For some reason the non-static variable that it is pointing at is "new". I am unclear of how I can fix this error as new is not meant to be a variable, and is not.

Looking through the stackoverflow records this error usually comes from a non-static method which is usually solved by making the method static or bypassing the method entirely. T

This code below is to reference what is going on before and after this statement.

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);
                System.out.println("Match Found");
                matchFound = true;
        BoardState addme = new BoardState();
        addme.str = x;
        addme.cnt = 1;



share|improve this question
possible duplicate of non-static variable cannot be referenced from a static context –  EJP Apr 12 '13 at 3:06

2 Answers 2

up vote 9 down vote accepted

The reason it doesn't work is because your class BoardState is an inner, non-static, class inside of IntelligentTicTacToe. This means that when referring to it, you'll be referring to an instance of the class; the instance isn't available from a static context.

One solution is to declare that class as:

public static class BoardState {

You can read more on inner classes here.

share|improve this answer
works thanks! Easiest solution. Thank you for the explanation –  John Smith Apr 12 '13 at 3:10

Don't nest classes like you're doing. There's no need, and all it's going to do is to require that you create a BoardState object on top of an IntelligentTicTacToe instance, i.e.,

BoardState addme = new IntelligentTicTacToe(). new BoardState();

but this should not be a requirement of your program.

Solution: Put the BoardState class where it belongs, in its own file. Or make BoardState an enum, but then it should only hold constants.

share|improve this answer
No; just make it static. –  SLaks Apr 12 '13 at 3:03
@SLaks: Could do that too. Or better, make it an enum, then it's automatically static. –  Hovercraft Full Of Eels Apr 12 '13 at 3:04
going to try your solutions now –  John Smith Apr 12 '13 at 3:08

Your Answer


