-1

Here is my code:

    public void start(Stage stage) throws Exception { 
        DemoView appView = new DemoView();
        Scene scene = new Scene(appView.getView());
        final String uri = getClass().getResource("app.css").toExternalForm();
        scene.getStylesheets().add(uri);
        
        stage.setScene(scene);
        stage.setResizable(true);
        stage.setTitle("Character Generator");
        stage.show();
    }

It throws an epic combos of errors like:

Exception in Application start method
java.lang.reflect.InvocationTargetException

What am I doing wrong? The compiler reports me that the code I wrote is the one who needs to be fixed. If I run it with Java 1.8 everything works, but when I compile it and run with Java 17 it crashes. If I try to run it from Java 10 to upper, it neither compiles it, just crashes with this error. The incriminated line should be:

        Scene scene = new Scene(appView.getView());
  • 3
    Edit the question, post the full stack trace. Provide a [mcve],minimal code which does *nothing* more than produce the error via copy and paste with no change or addition. – jewelsea Feb 13 '22 at 12:04
  • 1
    It could be that you need to open your controller package to your fxml file, but there are other reasons it may fail which might be revealed by either your code or your full stack trace. Study [Java 9 modules and add the appropriate module-info.java to your project](https://stackoverflow.com/a/57897944/1155209). – jewelsea Feb 13 '22 at 12:20

1 Answers1

-1

The use of reflection in Java has been restricted in Java 17.

Take a look into this Oracle blog post for further information. A peek into Java 17: Encapsulating the Java runtime internals

To figure out the cruel pit of your code, extract the nested Exception using

try {
    Scene scene = new Scene(appView.getView());
}
catch (InvocationTargetException ex) {
    System.err.println(ex.getCause());
}
EVi1b7wO
  • 76
  • 5