0

Trying to visualize the Binary Search Tree with JavaFX. Working IDE is IntelliJ IDEA. Double checked source codes, but couldn't find any missing points or issues which can cause the error.

Whole source code can be seen in the following repo (BinarySearchTreeApplication Folder): https://github.com/af4092/Binary-Search-Tree.git

Error message:

"C:\Program Files\Java\jdk-19\bin\java.exe" "-javaagent:C:\Users\FAbdu\IntelliJ IDEA 2023.1\lib\idea_rt.jar=60595:C:\Users\FAbdu\IntelliJ IDEA 2023.1\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\FAbdu\.m2\repository\org\openjfx\javafx-controls\19\javafx-controls-19.jar;C:\Users\FAbdu\.m2\repository\org\openjfx\javafx-graphics\19\javafx-graphics-19.jar;C:\Users\FAbdu\.m2\repository\org\openjfx\javafx-base\19\javafx-base-19.jar;C:\Users\FAbdu\.m2\repository\org\openjfx\javafx-fxml\19\javafx-fxml-19.jar;C:\Users\FAbdu\.m2\repository\org\jetbrains\annotations\17.0.0\annotations-17.0.0.jar;C:\Users\FAbdu\.m2\repository\org\openjfx\javafx-media\21-ea+5\javafx-media-21-ea+5.jar;C:\Users\FAbdu\.m2\repository\org\jfxcore\javafx-media\18-ea+1\javafx-media-18-ea+1.jar;C:\Users\FAbdu\.m2\repository\org\jfxcore\javafx-graphics\18-ea+1\javafx-graphics-18-ea+1.jar;C:\Users\FAbdu\.m2\repository\org\jfxcore\javafx-base\18-ea+1\javafx-base-18-ea+1.jar -p C:\Users\FAbdu\.m2\repository\org\openjfx\javafx-base\19\javafx-base-19-win.jar;C:\Users\FAbdu\.m2\repository\org\jfxcore\javafx-base\18-ea+1\javafx-base-18-ea+1-win.jar;C:\Users\FAbdu\.m2\repository\org\openjfx\javafx-media\21-ea+5\javafx-media-21-ea+5-win.jar;C:\Users\FAbdu\.m2\repository\org\jfxcore\javafx-media\18-ea+1\javafx-media-18-ea+1-win.jar;C:\Users\FAbdu\.m2\repository\org\openjfx\javafx-graphics\19\javafx-graphics-19-win.jar;C:\Users\FAbdu\.m2\repository\org\jfxcore\javafx-graphics\18-ea+1\javafx-graphics-18-ea+1-win.jar;C:\Users\FAbdu\.m2\repository\org\openjfx\javafx-fxml\19\javafx-fxml-19-win.jar;C:\Users\FAbdu\.m2\repository\org\openjfx\javafx-controls\19\javafx-controls-19-win.jar;C:\Users\FAbdu\IdeaProjects\JavaFXprojects\target\classes -m com.special.effect.javafxprojects/com.special.effect.javafxprojects.BinarySearchTreeApplication.BSInterface
Exception in Application constructor
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1081)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class com.special.effect.javafxprojects.BinarySearchTreeApplication.BSInterface
    at javafx.graphics@19/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:891)
    at javafx.graphics@19/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
    at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.lang.IllegalAccessException: class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot access class com.special.effect.javafxprojects.BinarySearchTreeApplication.BSInterface (in module com.special.effect.javafxprojects) because module com.special.effect.javafxprojects does not export com.special.effect.javafxprojects.BinarySearchTreeApplication to module javafx.graphics
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:420)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:709)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:493)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:484)
    at javafx.graphics@19/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:803)
    at javafx.graphics@19/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
    at javafx.graphics@19/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics@19/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    at javafx.graphics@19/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics@19/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics@19/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    ... 1 more

Process finished with exit code 1

And this is the UI of the Application:

public class BSInterface extends Application {
    @Override
    public void start(Stage stage) throws Exception {
        BST<Integer> tree = new BST<>();

        BorderPane pane = new BorderPane();
        BSTbackend view = new BSTbackend(tree);
        pane.setCenter(view);

        TextField tfKey = new TextField();
        tfKey.setPrefColumnCount(3);
        tfKey.setAlignment(Pos.BASELINE_RIGHT);
        Button btnInsert = new Button("INSERT");
        Button btnDelete = new Button("DELETE");
        HBox hBox = new HBox(5);
        hBox.getChildren().addAll(new Label("Enter a key: "),
                tfKey, btnInsert, btnDelete);
        hBox.setAlignment(Pos.CENTER);
        pane.setBottom(hBox);

        btnInsert.setOnAction(e->{
            int key = Integer.parseInt(tfKey.getText());
            if(!tree.search(key)){
                view.displayTree();
                view.setStatus(key + " is not in the tree");
            }else{
                tree.delete(key);
                view.displayTree();
                view.setStatus(key + " is deleted from the tree");
            }
        });

        btnDelete.setOnAction(e->{
            int key = Integer.parseInt(tfKey.getText());
            if(!tree.search(key)){
                view.displayTree();
                view.setStatus(key + " is not in the tree");
            }else{
                tree.delete(key);
                view.displayTree();
                view.setStatus(key + " is deleted from the tree");
            }
        });

        Scene scene = new Scene(pane, 450, 250);
        stage.setTitle("BST Animation");
        stage.setScene(scene);
        stage.show();
    }
}
  • 3
    Add an appropriate `exports` directive to your `module-info.java` file. See [the documentation](https://openjfx.io/javadoc/19/javafx.graphics/javafx/application/Application.html) for details, under "Deploying an Application as a Module". – Slaw Apr 17 '23 at 06:13
  • thanks a lot, actually missed the 'module-info'. Was very helpful, thank you – Farkhod Abdukodirov Apr 17 '23 at 06:20

0 Answers0