JavaFX InvocationTargetException

后端 未结 1 511
攒了一身酷
攒了一身酷 2021-01-14 11:37

I have the code:

package core;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
         


        
1条回答
  •  孤城傲影
    2021-01-14 12:13

    You have not set a resources folder in your project structure in order the getResourse method to work.

    Since you don't have the common Java structure, try providing the full path instead:

    FXMLLoader loader = new FXMLLoader(new File("fullpath").toURI().toURL());
    Parent root = loader.load();
    

    And if you want your code to work, you should be having a structure like the following, where main.fxml is inside resources directory:

    You can set a folder as "Resources folder" here: Project Structure->Modules->Sources

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