Måns Nilsson Måns Nilsson - 5 months ago 44
Java Question

Non-static variable this not referenceable from a static context

I'm fairly new to Java, though I've programmed in C++ before. I've made a simple class in Java:

import java.util.ArrayList;

public class ATMServer {
private static ArrayList<ArrayList<String>> savedstates = new ArrayList<ArrayList<String>>();
private static ArrayList<String> temp = new ArrayList<String>();

public static void main(String[] args) {

But when I try to compile it, I get the error "Non-static variable this cannot be referenced from a static context" for all occurrences of 'this' in the code. What causes this problem?


Drop the (this.temp) notation, replacing it with simply temp.

this does not mean anything in a static function since there is no implied object instance passed to the function.