4

What is meant by this error:

Error: Main method not found in class Static.A, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application

I was trying to run a program Without main Method..

public class A
{
    static
    {
      System.out.println("Hello");
      System.exit(0);
     }
} 
Coder
  • 1,917
  • 3
  • 17
  • 33
Mukesh Patel
  • 41
  • 1
  • 1
  • 2

2 Answers2

2

If you want to run your program either you should have the main method or if it is a JavaFX application then you have to have the start method. According to your class, you don't have neither of the conditions. So that is why you get the error

0

This means you don't have a main method in your class as the error says. Replace the static with public static void main(String[] args) and it works. Also it is not possible to run a program without a main method.

Laurel
  • 5,965
  • 14
  • 31
  • 57
XtremeBaumer
  • 6,275
  • 3
  • 19
  • 65
  • "it is not possible to run a program without main method" is not actually true. From the [`java` tool documentation](http://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html#BGBCIEFC): "The `java` command can be used to launch a JavaFX application by loading a class that **either** has a `main()` method **or** that extends `javafx.application.Application`." (My emphasis.) – James_D Dec 02 '16 at 22:34