0

This is my main class for running a simple frame have been created by JavaFX but I got this error

Exception in Application start method Exception in thread "main"
java.lang.NoSuchMethodException: controller.TestFrame.main([Ljava.lang.String;)
    at java.lang.Class.getMethod(Class.java:1786)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:119)
public class TestFrame extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {

        primaryStage.setTitle("Frame1 Title");
        primaryStage.setScene(
                new Scene(
                        (Parent) FXMLLoader.load(getClass().getResource("/view/Frame1.fxml"))
                        , 400
                        , 500));
        primaryStage.show();

    }

}
5
  • 2
    You didn't declare any static method named main(), so why are you confused when it says that no such method exists? Did you try the JavaFX Hello World program in the documentation? You know, to see how it works. Commented Dec 11, 2016 at 10:01
  • this class extended Application class in JavaFX so writing main() method it is not necessary even if I write a main() method that invoke the Application.lunch() method I'll get so many other errors Commented Dec 11, 2016 at 10:08
  • Error message says you need a main() method. Sample "Hello World" program has a main() method. So, perhaps you should have a main() method? Or start the program another way? --- If adding a main() method gives you other errors, it's probably because those errors are there now, and when it gets past the first error, the others will occur. Don't blame the main() method for that. Commented Dec 11, 2016 at 10:12
  • Do you have all imports? docs.oracle.com/javase/8/javafx/api/javafx/application/… Commented Dec 11, 2016 at 10:20
  • yes,I have all imports.and in the bellow comment i explained which kind of errors I got after adding main() methods Commented Dec 11, 2016 at 10:28

1 Answer 1

1

If you want run this class directly, you must add this method to your class:

public static void main(String[] args) {
        launch(args);
}
Sign up to request clarification or add additional context in comments.

14 Comments

at controller.TestFrame.start(TestFrame.java:20) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191) ... 1 more
please post whole stacktrace.
Next time could you edit your answer to include the new information instead of posting it into the chat.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.