New Java programmers often encounter these messages when they attempt to run a Java program.
Error: Main met
Generally, it means the program you are trying to run does not have a "main" method. If you are going to execute a Java program, the class being executed must have a main
method:
For example, in the file Foo.java
public class Foo {
public static void main(final String args[]) {
System.out.println("hello");
}
}
This program should compile and run no problem - if main
was called something else, or was not static, it would generate the error you experienced.
Every executable program, regardless of language, needs an entry point, to tell the interpreter, operating system or machine where to start execution. In Java's case, this is the static method main
, which is passed the parameter args[]
containing the command line arguments. This method is equivalent to int main(int argc, char** argv)
in C language.