Welcome to the Ranch
DD is right. I think that is a misleading error message; it lets people think there is something “normal” about things being
static and beginners often change their instance methods to
static methods because then the compile‑time error goes away. It is normal for things to be associated with objects, because Java® is an object oriented language. So you call an instance method on an object, and an object is sometimes called an instance of this class. Now an instance method might need access to an instance field, and both the instance method and instance field can be accessed on each object. So, the number of different instance fields is equal to the number of instances. And therefore the number of different ways you can call an instance method is equal to the number of objects.
Now, a
static member of a class is different; there is one copy of it. There is one static field per class, irrespective of how many instances there are.
If there is one instance, there is one copy of the static field.
If there are two instances, there is one copy of the static field.
If there are three instances, there is one copy of the static field.
If there are four instances, there is one copy of the static field.
If there are a million instances, there is one copy of the static field.
If there are no instances, there is one copy of the static field.
And the same applies to static methods. So you have one static method and any number of instances. If there are multiple instances, you don't know which object to call the method on. If there are no instances,,, it is impossible to call the method at all. You can only call it if there is one instance, and a static method has no business trying to restrict the class to one instance. So you aren't allowed to derefeerence an instance member from a static context. I think it would be less confusing to say, “Instance method xyz() can only be called from an instance context”. As DD implied, the correct solution usually involves removing the keyword
static.