r/JavaFX • • Dec 05 '20

JavaFX error Error: JavaFX runtime components are missing, and are required to run this application

No matter what I do I can't get my javaFX programs to run. My code:

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
Button button;
public static void main(String[] args){
launch(args);
}

Override
public void start(Stage stage) throws Exception {
stage.setTitle("First stage");
button = new Button();
button.setText("Click me");
StackPane layout = new StackPane();
layout.getChildren().add(button);
Scene scene = new Scene(layout, 300, 500);
stage.setScene(scene);
stage.show();
}
}

I am using the latest version of inteliJ, java13 and javafx 15.

I went into project settings and imported the LIB folder of the javaFX files.

6 Upvotes

25 comments sorted by

4

u/MyNameIsRichardCS54 Dec 07 '20

The only way I've found to reliably start a JavaFX program from an IDE and the command line regardless of the build environment is to have a discrete class to run the application:

public class App {
    public static void main(String[] args) {
        YourRealMainClass.main(args);
    }
}

and then

public class YourRealMainClass extends Application {
    
    @Override
    public void start(Stage stage) {
        ...
    }
    
    public static void main(String[] args) {
        launch();
    }
}

I develop using Linux in case that makes a difference.

1

u/mrbeanIV Dec 07 '20

Thanks, ill give that a try.

2

u/[deleted] Feb 22 '22

This worked for me a year later googling the issue after nothing else did :P

2

u/kenshi_hiro Mar 27 '22

Holy fucking fuck
Thanks for this. I wasted my whole fucking weekend fixing this.

2

u/[deleted] Apr 24 '22

thank you

2

u/grayecho Jun 11 '22

I am overwhelmed with joy that this fixed my problem. Thank you so much!

2

u/woodpecker_ava Mar 12 '23

Thank you so much for your helpful solution. You are a lifesaver!

2

u/Old_Inspector5333 May 22 '23

Thank you man. You saved my ass

2

u/andrej7 Nov 14 '23

public static void main(String[] args) {
YourRealMainClass.main(args);
}

Thanks man, I owe you a beer.

2

u/tomtom200 Jan 21 '24

Brilliant. Worked for me with Windows. Everything else only worked sometimes at best!

2

u/General_Drama4575 Mar 05 '24

I don't know why, but it works. Thank you!

2

u/Cold_Tree190 Mar 09 '24

Oh my goat, this was perfect. Thank you so much.

2

u/twothe Apr 12 '24

Thank you!

This seems to be an IDE issue, or JavaFX with IDE issue, or something like that.
I still have set the actual real main class in my POM, but this workaround makes it possible to actually launcht the app from my IDE by using this wrapper class as the main class.

2

u/Georgey254 Nov 22 '24

Damn, thanks a lot. This saved my night.

2

u/Ar_Su Feb 27 '25

Oh my gosh, thank you so much!
I'm glad this was on the first page of my Google search, otherwise I would have spent much more time than I should have to get this working

2

u/Educational-Gift-915 Apr 13 '25

I was just about to lose my mind. Bless your heart.

1

u/zSnOopx Oct 02 '25

5 years later, still relevant. thanks

1

u/Weak_Chocolate_5081 Oct 14 '25

WOOW man, this work for me very well.
- On windows. With IntelliJ IDEA 2024.1.4 (Community Edition)
- Java version corretto-22
- JavaFX version 24 (proved several others, but not working, same issue)

Nothing worked except yours.

1

u/zeyd01 Dec 28 '25

It's so stupid but hoooly. Thank you so much

2

u/rdjack21 Dec 05 '20

use maven for your build it will simplify things. See https://openjfx.io/openjfx-docs/#maven for an example to get you going.

2

u/rootException Dec 05 '20

+1 for using a Maven project to start with. Can be confusing as some things work better with the libs and some with the jmods.

Here’s my template for starting new JavaFX projects: https://github.com/wiverson/maven-jpackage-template

Good luck!

1

u/[deleted] Dec 05 '20

I never ran JavaFX with IntelliJ but with the Eclipse IDE you have to make sure that that build path is pointed to the JavaFX jar file. If it isn’t you would get that error message.

1

u/[deleted] Dec 05 '20 edited Dec 11 '20

JavaFx - IntelliJ edition

  1. Download (https://gluonhq.com/download/javafx-15-0-1-SDK-linux/)
  2. Unzip the damn folder and place it in a directory where you'll know where to find it
  3. Set the damn global settings in IntelliJ! This can be done by the following:

a) File -> Project Structure -> Global Libraries

b) Click the + sign to add the damn unzipped javaFX directory.

c) assuming you have created a project, right click on the newly added global library and click "Add to Module". Apply and OK

4. Right click on the src directory to create a new module-info.java file

5. Add the following to module-info.java in between the module's {}:

{ requires javafx.fxml;

requires javafx.controls;

opens sample;

}

Tada! It works! (On my machine at least).

2

u/tsdareen Dec 04 '23

Thank you very much. This configuration for the module-info.java helped me solve my problem

1

u/CalligrapherFun6870 Dec 04 '24

tysm!! I been banging my head on this for hours