java error cannot make a static reference to the non-static field v

outputMethod is a static method. Those variable members aren’t static, which means they are not held by the class but by instances of the class. So you can’t access them without instantiating an object of the class Tables.

Alternatively you can make them static:

class MyClass {
    public static double v;
    public static void outputMethod() {
        // You can access v now from here

Leave a Comment