2
1

More than 5 years have passed since last update.

Java10+Eclipseで、JavaFXを使ったときにハマったところを書いておく

Last updated at Posted at 2018-08-20

超初心者用チュートリアルをみながらつくったらハマる要素があったので覚え書きです。

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;
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1