InvocationTargetException when running a javafx program

前端 未结 6 1916
野的像风
野的像风 2020-11-30 10:05

So this worked in the example from javafx when My pc had jdk 1.7.0 so this may be the new version of FX in java8 however;

I get a nice stack-trace

jf         


        
6条回答
  •  迷失自我
    2020-11-30 10:17

    I faced the same problem and want to share a little bit related to it. I'm using java 8 and Netbeans 8.1 and when I created a javafx FXML Application I got this one.
    Here are some tips:

    1. When you create new project clean and build your project before you try to run.
    2. If you rename any file (controller, fxml) IDE do not apply changes to other files at least Netbeans is not doing so. So, you have to change those file names in other files manually.
    3. You can define controller either in fxml file or in main class. If you want to define controller in main class use the method described by @James_D. If you want to define in fxml file than use fx:controller attribute as

       fx:controller="yourProjectName.yourFXMLDocumentControllerName"
      

      and in main class reference it as

      Parent root = FXMLLoader.load(getClass().getResource("yourFXMLFileName.fxml"));
      
    4. If you think everything is correct but you still getting the error clean and build your project again and try to run.

    Hope it would help someone.

提交回复
热议问题