Main method not found JavaFX application class

In Java, each application must have the main method. The main method indicates the start of the application. The java program searches for the main method while running. This error occurred when the main method is not available.



Exception

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


Error Code

The Error code looks like as below

package com.yawintutor;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringHelloWorldApplication {

}


Root Cause

Spring boot is looking for the main method to start the spring boot application. This error occurred because the main method is not available.

Any one of the following is the possible cause of this issue

  • The main method is deleted
  • The main method name is renamed
  • The signature of the main method is changed
public static void main(String[] args) {
// block of code 		
}


Solution

If the main method is not available, add the main method as shown in the above

If the main method name is renamed or altered, correct the main method name

Check the main method in the spring boot application and modify it as shown in the below example

package com.yawintutor;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringHelloWorldApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringHelloWorldApplication.class, args);
	}

}

How to create simple Spring Boot Application with Main method



Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *