0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

jarを実行するとjava.lang.NullPointerException: Location is required.が出る

Last updated at Posted at 2021-02-19

#エラー内容

■ビルドは通るが、jarにすると下記のエラーが出る
Caused by: java.lang.NullPointerException: Location is required.
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
        at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
        at code.Main.start(Main.java:13)

■ソースの階層
src
 ∟codeフォルダー
  ∟main.class
  ∟controller.class
 ∟fxmlフォルダー
  ∟mainView.fxml

■該当のソースコード
Parent root = FXMLLoader.load(getClass().getResource("../fxml/mainView.fxml"));

#とりあえずの解決
【../fxml/mainView.fxml】
fxmlを呼び出すときに上階層だと読めない?

■ソースの構造を変える
fxmlフォルダーをcodeフォルダーの中に入れる
src
 ∟codeフォルダー
  ∟main.class
  ∟controller.class
  ∟fxmlフォルダー
   ∟mainView.fxml

コードの変更
【../】を削除する
Parent root = FXMLLoader.load(getClass().getResource("fxml/mainView.fxml"));

jarが実行できた!

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?