Posted on 17th September 2024|1151 views
While I’m working on a Java program, I got this compiler error: non-static variable count can not be referenced from a static context. Can anyone tell me What does it mean, why this error occurs, and How to fix this error?
Posted on 17th September 2024| views
Hey Kusum,
The non-static variable cannot be referenced from a static context is compiler error that occurs when the user tries to put program code to access a non-static variable inside main in Java that is static.
public class Static Test{
Private int count=0;
public static void main(String args[]) throws IOException{
count++; //compiler error: non-static variable count cannot be referenced from a static context
}
}