超初心者用チュートリアルをみながらつくったらハマる要素があったので覚え書きです。
fxmlファイルにcontrollerを指定する
例
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainController">
デザインの一番上のタグにfx:controllerで、コントローラのクラスを指定しておかないとアクションを追加したときにロード・エラーが出る。(上ではコントローラをapplication.MainController classに実装している。)
fx:controller="application.MainController"
参考:https://stackoverflow.com/questions/33881046/how-to-connect-fx-controller-with-main-app
この辺とか
module-infoにjavafx.fxmlのアクセス許可をかく。
例
module webtest {
exports application;
requires javafx.base;
requires javafx.controls;
requires javafx.fxml;
requires javafx.graphics;
requires javafx.web;
opens application to javafx.fxml;
}
どうやらJava9以上の場合はこれを入れておかないとjava.lang.reflect.InaccessibleObjectExceptionが置きるようです。
参考:https://aoe-tk.hatenablog.com/entry/2017/12/01/000135
opens <コントローラのパッケージ名> to javafx.fxml;