0

It's giving me this error

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at javafx.graphics@20.0.1/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics@20.0.1/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1082)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics@20.0.1/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
    at javafx.graphics@20.0.1/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalAccessError: class com.sun.media.jfxmediaimpl.NativeMediaManager (in unnamed module @0x7b61a0ef) cannot access class com.sun.glass.utils.NativeLibLoader (in module javafx.graphics) because module javafx.graphics does not export com.sun.glass.utils to unnamed module @0x7b61a0ef
    at com.sun.media.jfxmediaimpl.NativeMediaManager.lambda$new$0(NativeMediaManager.java:110)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
    at com.sun.media.jfxmediaimpl.NativeMediaManager.<init>(NativeMediaManager.java:107)
    at com.sun.media.jfxmediaimpl.NativeMediaManager$NativeMediaManagerInitializer.<clinit>(NativeMediaManager.java:77)
    at com.sun.media.jfxmediaimpl.NativeMediaManager.getDefaultInstance(NativeMediaManager.java:89)
    at com.sun.media.jfxmedia.MediaManager.canPlayProtocol(MediaManager.java:78)
    at com.sun.media.jfxmedia.locator.Locator.<init>(Locator.java:240)
    at javafx.scene.media.Media.<init>(Media.java:392)
    at Final.StageEleven(Final.java:288)
    at Final.start(Final.java:37)
    at javafx.graphics@20.0.1/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
    at javafx.graphics@20.0.1/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
    at javafx.graphics@20.0.1/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics@20.0.1/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
    at javafx.graphics@20.0.1/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at javafx.graphics@20.0.1/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics@20.0.1/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:185)
    ... 1 more
Exception running application Final
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import java.io.File;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;

public class Final extends Application{

    private Label outputmessage;
    private ImageView BannerImage1, BannerImage2, BannerImage3; 
    private Image image1,image2,image3;
    private GridPane Grid;
    private Stage stage;
    private Button button1, button2, button3; 
    private Scene scene1,scene2,scene3,scene4,scene5,scene6,scene7,scene8,
        scene9,scene10,scene11,scene12,scene13, scene14,scene15,scene16,scene17,scene18,scene19,scene20;
    public void start(Stage primarystage) throws Exception
    {
        stage = primarystage;
        stage.setTitle("The World of Leway");
        scene1 = Stageone();
        scene2 = Stagetwo();
        scene3 = StageThree();
        scene4 = StageFour();
        scene5 = StageFive();
        scene6 = StageSix();
        scene7 = StageSeven();
        scene8 = StageEight();
        scene9 = StageNine();
        scene10 = StageTen();
        scene11 = StageEleven();
        scene12 = StageTwelve();
        scene13 = StageThirteen();
        scene14 = StageFourteen();
        scene15 = StageFifteen();
        scene16 = StageSixteen();
        scene17 = StageSeventeen();
        scene18 = StageEighteen();
        scene19 = StageNineteen();
        scene20 = StageTwenty();
        stage.setScene(scene1);
        stage.show();
    }
    private Scene Stageone()
    {
        outputmessage = new Label("You soon begin to wake up in a room, sitting on a chair, from behind you hear a woman's voice saying, 'You have died.' A woman with blue hair walked past you, taking a seat in front you."
                + "\nAs she sat, she spoke once more, 'After dying I have taken your soul and brought it to this world. You can say it's sort of a limbo. My name is Aqua. I have summoned you here to ask you one thing.'");
        image1 = new Image("file:Goddess.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        button1 = new Button("Next");
        button1.setOnAction(e -> switchScenes(scene2));
        Grid = new GridPane();
        Grid.add(BannerImage1, 1, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 1, 2);
        return scene1;
    }
    
    private Scene Stagetwo()
    {
        outputmessage = new Label("Please take up arm and defeat the demon lord of this world. You can choose between these three weapons.");
        image1 = new Image("file:greatsword.jpeg");
        image2 = new Image("file:SwordandShield.jpg");
        image3 = new Image("file:bow.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage2 = new ImageView(image2);
        BannerImage3 = new ImageView(image3);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        BannerImage2.setFitWidth(100);
        BannerImage2.setFitHeight(100);
        BannerImage3.setFitWidth(100);
        BannerImage3.setFitHeight(100);
        button1 = new Button("Great Sword");
        button2 = new Button("Sword and Shield");
        button3 = new Button("Bow");
        button1.setOnAction(e -> switchScenes(scene3));
        button2.setOnAction(e -> switchScenes(scene3));
        button3.setOnAction(e -> switchScenes(scene3));
        Grid = new GridPane();
        Grid.add(BannerImage1, 0, 0);
        Grid.add(BannerImage2, 1, 0);
        Grid.add(BannerImage3, 2, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 0, 2);
        Grid.add(button2, 1, 2);
        Grid.add(button3, 2, 2);
        return scene2;
    }
    
    private Scene StageThree()
    {
        outputmessage = new Label("After having picked your weapon, you soon are engulfed in a bright light and after the light disapates you appear in the middle of a city."
                + "\nAfter walking around for a while, taking in the sights of a different world and city, you are soon stopped by a knight of the city. he begans to ask a series of questions, until he spots your weapon. 'Please Come with me.'"
                + "\nHe said as lead you to the castle in the middle of the city.");
        image1 = new Image("file:CityStreets.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        button1 = new Button("Next");
        button1.setOnAction(e-> switchScenes(scene4));
        Grid = new GridPane();
        Grid.add(BannerImage1, 1, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 1, 2);
        return scene3;
    }
    
    private Scene StageFour()
    {
        outputmessage = new Label("Meeting with king");
        image1 = new Image("file:king.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        button1 = new Button("Next");
        button1.setOnAction(e-> switchScenes(scene5));
        Grid = new GridPane();
        Grid.add(BannerImage1, 1, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 1, 2);
        return scene4;
    }
    
    private Scene StageFive()
    {
        outputmessage = new Label("Training Path");
        image1 = new Image("file:denseforest.jpg");
        image2 = new Image("file:lightforest.jpg");
        image3 = new Image("file:demonlordcastle.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage2 = new ImageView(image2);
        BannerImage3 = new ImageView(image3);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        BannerImage2.setFitWidth(100);
        BannerImage2.setFitHeight(100);
        BannerImage3.setFitWidth(100);
        BannerImage3.setFitHeight(100);
        button1 = new Button("Train Hard");
        button2 = new Button("Train Light");
        button3 = new Button("Straight for demon king");
        button1.setOnAction(e -> switchScenes(scene6));
        button2.setOnAction(e -> switchScenes(scene7));
        button3.setOnAction(e -> switchScenes(scene8));
        Grid = new GridPane();
        Grid.add(BannerImage1, 0, 0);
        Grid.add(BannerImage2, 1, 0);
        Grid.add(BannerImage3, 2, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 0, 2);
        Grid.add(button2, 1, 2);
        Grid.add(button3, 2, 2);
        return scene5;
    }
    
    private Scene StageSix()
    {
        outputmessage = new Label("Go down training hard path and walk around, which path you take");
        image1 = new Image("file:right.jpg");
        image2 = new Image("file:middle.jpg");
        image3 = new Image("file:left.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage2 = new ImageView(image2);
        BannerImage3 = new ImageView(image3);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        BannerImage2.setFitWidth(100);
        BannerImage2.setFitHeight(100);
        BannerImage3.setFitWidth(100);
        BannerImage3.setFitHeight(100);
        button1 = new Button("Right");
        button2 = new Button("Middle");
        button3 = new Button("Left");
        button1.setOnAction(e -> switchScenes(scene9));
        button2.setOnAction(e -> switchScenes(scene20));
        button3.setOnAction(e -> switchScenes(scene11));
        Grid = new GridPane();
        Grid.add(BannerImage1, 0, 0);
        Grid.add(BannerImage2, 1, 0);
        Grid.add(BannerImage3, 2, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 0, 2);
        Grid.add(button2, 1, 2);
        Grid.add(button3, 2, 2);
        return scene6;
    }
    
    private Scene StageSeven()
    {
        outputmessage = new Label("go down Train lightly path, which way");
        image1 = new Image("file:right.jpg");
        image2 = new Image("file:middle.jpg");
        image3 = new Image("file:left.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage2 = new ImageView(image2);
        BannerImage3 = new ImageView(image3);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        BannerImage2.setFitWidth(100);
        BannerImage2.setFitHeight(100);
        BannerImage3.setFitWidth(100);
        BannerImage3.setFitHeight(100);
        button1 = new Button("Right");
        button2 = new Button("Middle");
        button3 = new Button("Left");
        button1.setOnAction(e -> switchScenes(scene15));
        button2.setOnAction(e -> switchScenes(scene10));
        button3.setOnAction(e -> switchScenes(scene11));
        Grid = new GridPane();
        Grid.add(BannerImage1, 0, 0);
        Grid.add(BannerImage2, 1, 0);
        Grid.add(BannerImage3, 2, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 0, 2);
        Grid.add(button2, 1, 2);
        Grid.add(button3, 2, 2);
        return scene7;
    }
    
    private Scene StageEight()
    {
        outputmessage = new Label("go straight for demon lord");
        image1 = new Image("file:demonlordcastle.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        button1 = new Button("Next");
        button1.setOnAction(e-> switchScenes(scene18));
        Grid = new GridPane();
        Grid.add(BannerImage1, 1, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 1, 2);
        return scene8;
    }
    private Scene StageNine()
    {
        outputmessage = new Label("Run into a group of orcs and beat them easily. You go back to looking find another fork, which path");
        image1 = new Image("file:right.jpg");
        image2 = new Image("file:left.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage2 = new ImageView(image2);
        BannerImage3 = new ImageView(image3);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        BannerImage2.setFitWidth(100);
        BannerImage2.setFitHeight(100);
        button1 = new Button("Left");
        button2 = new Button("Right");
        button1.setOnAction(e -> switchScenes(scene12));
        button2.setOnAction(e -> switchScenes(scene11));
        Grid = new GridPane();
        Grid.add(BannerImage1, 0, 0);
        Grid.add(BannerImage2, 1, 0);
        Grid.add(BannerImage3, 2, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 0, 2);
        Grid.add(button2, 1, 2);
        return scene9;
    }
    
    private Scene StageTen()
    {
        outputmessage = new Label("After looking for something to fight around the forest, you were turned around and wnet around in a circle.");
        image1 = new Image("file:denseforest.jpg");
        BannerImage1.setFitHeight(100);
        BannerImage1.setFitWidth(100);
        button1 = new Button("Next");
        button1.setOnAction(e -> switchScenes(scene5));
        Grid = new GridPane();
        Grid.add(BannerImage1, 1, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 1, 2);
        return scene10;
    }
    
    private Scene StageEleven()
    {
        String gos = "gos.mp3";
        Media hit = new Media(new File(gos).toURI().toString());
        MediaPlayer mediaplayer = new MediaPlayer(hit);
        mediaplayer.play();
        outputmessage = new Label("You have run into a large demon king patrol unit and were killed.");
        image1 = new Image("gameover.jpg");
        BannerImage1 = new ImageView(image1);
        button1 = new Button("Retry?");
        button1.setOnAction(e -> switchScenes(scene1));
        Grid = new GridPane();
        Grid.add(BannerImage1, 1, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 1, 2);
        return scene11;
    }
    
    private Scene StageTwelve()
    {
        outputmessage = new Label("Find dragon and beat it with ease as you attune to your weapon, awakening it's full potentail, which way do you go.");
        image1 = new Image("file:right.jpg");
        image2 = new Image("file:left.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage2 = new ImageView(image2);
        BannerImage3 = new ImageView(image3);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        BannerImage2.setFitWidth(100);
        BannerImage2.setFitHeight(100);
        button1 = new Button("Right");
        button2 = new Button("Left");
        button1.setOnAction(e -> switchScenes(scene11));
        button2.setOnAction(e -> switchScenes(scene13));
        Grid = new GridPane();
        Grid.add(BannerImage1, 1, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 0, 2);
        Grid.add(button2, 1, 2);
        return scene12;
    }
    
    private Scene StageThirteen()
    {
        outputmessage = new Label("Meeting the demon king");
        image1 = new Image("file:DMPic.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        button1 = new Button("Next");
        button1.setOnAction(e-> switchScenes(scene14));
        Grid = new GridPane();
        Grid.add(BannerImage1, 1, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 1, 2);
        return scene13;
    }
    
    private Scene StageFourteen()
    {
        outputmessage = new Label("Good Ending");
        image1 = new Image("goodending.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        Grid = new GridPane();
        Grid.add(BannerImage1, 1, 0);
        Grid.add(outputmessage, 1, 1);
        return scene14;
    }
    
    private Scene StageFifteen()
    {
        outputmessage = new Label("Finding a group of orcs, which path will you take");
        image1 = new Image("file:right.jpg");
        image2 = new Image("file:left.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage2 = new ImageView(image2);
        BannerImage3 = new ImageView(image3);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        BannerImage2.setFitWidth(100);
        BannerImage2.setFitHeight(100);
        button1 = new Button("Right");
        button2 = new Button("Left");
        button1.setOnAction(e -> switchScenes(scene11));
        button2.setOnAction(e -> switchScenes(scene16));
        Grid = new GridPane();
        Grid.add(BannerImage1, 0, 0);
        Grid.add(BannerImage2, 1, 0);
        Grid.add(BannerImage3, 2, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 0, 2);
        Grid.add(button2, 1, 2);
        return scene15;
    }
    
    private Scene StageSixteen()
    {
        outputmessage = new Label("Meeting the demon king");
        image1 = new Image("file:DMPic.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        button1 = new Button("Next");
        button1.setOnAction(e-> switchScenes(scene17));
        Grid = new GridPane();
        Grid.add(BannerImage1, 1, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 1, 2);
        return scene16;
    }
    
    private Scene StageSeventeen()
    {
        outputmessage = new Label("Neutrual Ending");
        image1 = new Image("file:neutrualending.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        Grid = new GridPane();
        Grid.add(BannerImage1, 1, 0);
        Grid.add(outputmessage, 1, 1);
        return scene17;
    }
    
    private Scene StageEighteen()
    {
        outputmessage = new Label("go straight for demon lord");
        image1 = new Image("file:DMPic.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        button1 = new Button("Next");
        button1.setOnAction(e-> switchScenes(scene19));
        Grid = new GridPane();
        Grid.add(BannerImage1, 1, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 1, 2);
        return scene18;
    }
    
    private Scene StageNineteen()
    {
        outputmessage = new Label("Bad Ending");
        image1 = new Image("badending.jpg");
        BannerImage1 = new ImageView(image1);
        BannerImage1.setFitWidth(100);
        BannerImage1.setFitHeight(100);
        Grid = new GridPane();
        Grid.add(BannerImage1, 1, 0);
        Grid.add(outputmessage, 1, 1);
        return scene19;
    }

    private Scene StageTwenty()
    {
        outputmessage = new Label("After looking for something to fight around the forest, you were turned around and wnet around in a circle.");
        image1 = new Image("file:lightforest.jpg");
        BannerImage1.setFitHeight(100);
        BannerImage1.setFitWidth(100);
        button1 = new Button("Next");
        button1.setOnAction(e -> switchScenes(scene7));
        Grid = new GridPane();
        Grid.add(BannerImage1, 1, 0);
        Grid.add(outputmessage, 1, 1);
        Grid.add(button1, 1, 2);
        return scene20;
    }
    
    public void switchScenes(Scene scene)
    {
        stage.setScene(scene);
    }
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        launch(args);

    }
}

I have already set up the run config and all that.

SedJ601
  • 12,173
  • 3
  • 41
  • 59
  • Does this help ? https://stackoverflow.com/questions/69779045/stuck-on-javafx-graphics-does-not-export-com-sun-javafx-sg-prism-to-unnamed-modu – Arpit Saxena May 05 '23 at 14:48
  • It looks like the module file needs to be set up. Also worth pondering if this project needs to be modular. – DaveB May 05 '23 at 16:19
  • @DaveB "_Also worth pondering if this project needs to be modular_" -- Given the nature of the error, the OP's code is already non-modular. Or at least not being launched as a module (i.e., if the OP has a `module-info.java` file, then it's being ignored). Unless you mean something else (e.g., though technically unsupported, place JavaFX on the class-path instead of the module-path)? – Slaw May 05 '23 at 19:49
  • @Slaw, don't you get the, "does not export ... to unamed module", error when you have a module-info.java file but it's missing some export statements? I'm also thinking that you can define a project as modular in a Gradle build, but still leave out the module-info.java file - in which case you would get the same errors. – DaveB May 05 '23 at 20:40
  • @DaveB This error specifically is occurring because `javafx.media` has been placed on the class-path and become part of the unnamed module, yet `javafx.graphics` was placed on the module-path and resolved as a named module, and so the _qualified_ exports defined by `javafx.graphics` that export certain things to `javafx.media` no longer work properly. The first duplicate goes into more detail. – Slaw May 06 '23 at 04:43
  • Code without a module-info descriptor that is placed on the module-path and resolved as a module becomes an "automatic module", which is still a _named_ module. Though I'm not sure if that can apply to the "main module" (i.e., can `--module` target an automatic module?). An unnamed module is where all code on the class-path ends up (and which any module-info descriptor in such code is ignored; this is how you can use modular dependencies as if they weren't modular). And if **your** module-info descriptor(s) was "missing" `exports` directives, then I'd expect a _compilation_ error. – Slaw May 06 '23 at 04:49

0 Answers0