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

前端 未结 10 1761
刺人心
刺人心 2021-01-02 18:47

I am just starting out with JavaFX, and I am trying to build a simple application with a label, text field and button which, when clicked, sets the label\'s value to that of

相关标签:
10条回答
  • 2021-01-02 19:25

    Another cause might be missing VM options:

    --module-path <path-to-javafx>/javafx-sdk-11.0.2/lib 
    --add-modules=javafx.controls,javafx.fxml
    
    0 讨论(0)
  • 2021-01-02 19:31

    For anyone who has this exact same problem in the future, as James_D and the other answer contributors mentioned, removing the "/" at the beginning of the path fixes the problem so use

    FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindowView.fxml"));
    

    instead of

    FXMLLoader loader = new FXMLLoader(Main.class.getResource("/MainWindowView.fxml"));
    
    0 讨论(0)
  • 2021-01-02 19:31

    I've been looking through this thread and the answers but the cases are a bit different for me

    the code written in the main file is not as mentioned like this:

    FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindowView.fxml"));
    

    the code in my case is like this:

    FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
    

    and I encountered the same error(approx.)

    0 讨论(0)
  • 2021-01-02 19:35

    guess its this ?

    @FXML
    void handleButton(ActionEvent event) {
    
    0 讨论(0)
  • 2021-01-02 19:35

    The same problem happened to me. It's because of maven library. I have different version of jfoenix library in scene builder jfoenix:0.1.8 and in IDE jfoenix:9.0.9.so i downloaded the same version in both and it worked for me.

    And also for the nullpointer exception this code worked for me:

    FXMLLoader fxmlLoader=new FXMLLoader (Main.class.getResource ("sample.fxml"));
    Parent root =fxmlLoader.load ();
    

    The fxml file and Main is in same package.

    0 讨论(0)
  • 2021-01-02 19:36

    Perform the following operation

    FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindowView.fxml"));
    Parent root =  loader.load();
    

    Remove / from in front of .fxml file name. I think it should work. It solved the same error for me.

    0 讨论(0)
提交回复
热议问题