Search code examples
javanon-static

Java: error - non-static variable scan cannot be referenced from a static context


I have this error:

non-static variable scan cannot be referenced from a static context


Question has been improved.

1) Posted a code instead of a pic.

2) Improved a formatting and question itself.


Solution

  • Try to declare the class variables as static. So you will have:

    static char val;
    static Scanner scan = new Scanner(System.in);