Java compile error: non-static method cannot be referenced from a static context – what causes it?

Tutoring Java programming, this error message might come up. The tutor talks about a couple of its causes.

The message

error: non-static method MethodX() cannot be referenced from a static context

has a couple of causes I know:

  1. The class that contains the static main method contains another method other_method that isn’t static. other_method can’t be called from the static one unless it, too, is declared static.
  2. An object has been created [Objectx Ox = new Objectx();], but then its method methodx() is called using the class name [Objectx.methodx();]
    as opposed to the instance name [Ox.methodx();]

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply