Your error message can be explained as follows:
In Java, functions, fields and inner classes can be static if they use the modifier
static. These functions / fields / classes do then not belong to an instance of the wrapping class but rather to the outer class itself. Let me give you an example:
- public class Example {
-
public static void sayHelloStatic() {
-
System.out.println("Hello!");
-
}
-
-
public void sayHelloNonStatic() {
-
System.out.println("Hello!");
-
}
-
}
Now you can use those methods like so:
- //...
-
Example.sayHelloStatic();
-
//...
-
Example ex = new Example();
-
ex.sayHelloNonStatic();
-
//...
You see, for the second one you need an instance of that class while you don't for the first.
The error you're getting occurs when you are trying to call a non-static function from a static one without creating an instance of that object to use it from. This quite often happens in the main function (which is static). So the solution would be
- to create an instance of the object and use the function from there or
- make the function static
In many cases the first solution is to be preferred but there can be very good reasons to go with the second one too.