Why am i getting 'error: modifier static not allowed here' in java?

Example:

public class Test {
    public void myMethod() {
        static int x = 10;
    }
}

You're trying to declare a local variable as static inside a method which isn't allowed.

Solution:

Remove the static modifier from the local variable.


public void myMethod() {
    int x = 10;
}

Beginner's Guide to Java