Error on javafx

Anouchka2586 Posted messages 47 Registration date   Status Member Last intervention   -  
Anouchka2586 Posted messages 47 Registration date   Status Member Last intervention   -
Hello,

I have this error with the code below:
Error: Could not find or load main class application.Main
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application


 package application; import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.shape.Rectangle; import javafx.scene.shape.Shape; public class Main extends Application { @Override public void start(Stage primaryStage) { try { Group root = new Group(); Scene scene = new Scene(root,800,800); Shape s = new Shape(); Rectangle r = new Rectangle(); r.setX(750); r.setY(100); r.setWidth(200); r.setHeight(100); r.setArcWidth(30); r.setArcHeight(20); root.getChildren().add(r); primaryStage.setScene(scene); primaryStage.setTitle("Hello world"); primaryStage.show(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { launch(args); } } 


Thank you for your help!

3 answers

  1. KX Posted messages 19031 Status Moderator 3 020
     
    Hello,

    Which version of Java are you coding with?
    Since Java 11, Java FX is no longer included in the JDK; it is managed separately, as was already the case before Java 8.
    See https://openjfx.io
    --
    Trust does not exclude control.
    0
  2. Anouchka2586 Posted messages 47 Registration date   Status Member Last intervention   5
     
    I am on version 14. I followed this tutorial: https://openjfx.io/openjfx-docs/ to install JavaFX but I have this error:
    Error: Could not find or load main class Files
    Caused by: java.lang.ClassNotFoundException: Files
    0
    1. KX Posted messages 19031 Status Moderator 3 020
       
      It seems that this is related to the installation directory
      C:/Program Files
      because of the space.
      Generally, we put quotes around a path that contains spaces. In this particular case, we could use
      C:/PROGRA~1
      which is an alias. Otherwise, you can try with an installation in a directory without spaces.
      0
  3. Anouchka2586 Posted messages 47 Registration date   Status Member Last intervention   5
     
    Yes, exactly I put it on the desktop, there should be no spaces in the names of the directories where javafx is.
    0