加载FXML文件时出现JavaFX LoadException

时间:2017-06-01 12:38:59

标签: java javafx scenebuilder

每次运行JavaFX应用程序时,都会遇到以下错误。

15:11:52.778 [JavaFX Application Thread] ERROR org.fhl.Manifesto - javafx.fxml.LoadException: 
/C:/ManGenFX/target/classes/dataController.fxml
/C:/ManGenFX/target/classes/ManifestoMain.fxml:7

但只有在主控制器上添加initialize方法才会发生。

    public class MainController{

        @FXML
        GenerateController genCont;

        @FXML
        private Pane generatePane;
        @FXML
        AnchorPane mainFx;

        private Node source;

    //Other Button, TextFields and Labels declaration

    @FXML
    private void browseFile(ActionEvent x) {
    //Browse file definition
    }

    @FXML
    private void savePath(ActionEvent x) {
    //Save file definition
    }

//Problem with this method
    @FXML
    public void initialize() {
        System.out.println("Initialize generate controller panel");
        logger.info("Initialize generate controller panel");

        genCont.init(this);

        }
    }

如果我在MainController类上删除了initialize方法,它将不会抛出任何错误,但是如果我点击下面的GenerateController类中定义的generate按钮,则没有任何反应。

public class GenerateController {
    @FXML
    Button btnGenerate;
    @FXML
    Pane paneGen;

    @FXML
    public void generateMan(ActionEvent event) {

//generateMan body when Generate button is clicked

    }

    public void init(MainController mc) {
        System.out.println("Init mainControl");
        mainControl = mc;

    }

public void validate() {
//Definition of method body here
  }
}

这是主要的课程

public class Man extends Application {

    private Stage mainStage;

    @Override
    public void start(Stage primaryStage) {

        this.mainStage = primaryStage;
        this.mainStage.setTitle("Manifest");

        try{

            Parent root = FXMLLoader.load(getClass().getResource("/ManifestoMain.fxml"));

            Scene sMain = new Scene(root);

            mainStage.setScene(sMain);

            mainStage.show();

        }catch(IOException ioE) {
            logger.error(ioE);
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

另外,我在data资源文件夹下放置了dataController.fxml,ManifestoMain.fxml和generateView.fxml,但访问文件时没有任何问题。对此表示感谢。

0 个答案:

没有答案