前提・実現したいこと
JavaFX,SceneBuilderを使用して、windowにHello,World!を表示するプログラムを作りたい。
発生している問題・エラーメッセージ
Exception in Application start method java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464) at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051) Caused by: java.lang.RuntimeException: Exception in Application start method at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900) at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x4f80e47b) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x4f80e47b at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38) at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056) at application.Main.start(Main.java:14) at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428) at java.base/java.security.AccessController.doPrivileged(Native Method) at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427) at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96) at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174) ... 1 more Exception running application application.Main
該当のソースコード
Main.java
1package application; 2 3import javafx.application.Application; 4import javafx.fxml.FXMLLoader; 5import javafx.scene.Scene; 6import javafx.scene.layout.BorderPane; 7import javafx.stage.Stage; 8 9 10public class Main extends Application { 11 @Override 12 public void start(Stage primaryStage) { 13 try { 14 BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("Sample.fxml")); 15 Scene scene = new Scene(root,400,400); 16 scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); 17 primaryStage.setScene(scene); 18 primaryStage.show(); 19 } catch(Exception e) { 20 e.printStackTrace(); 21 } 22 } 23 24 public static void main(String[] args) { 25 launch(args); 26 } 27} 28
SampleController.java
1package application; 2 3import java.net.URL; 4import java.util.ResourceBundle; 5 6import javafx.fxml.FXML; 7 8public class SampleController { 9 10 @FXML 11 private ResourceBundle resources; 12 13 @FXML 14 private URL location; 15 16 @FXML 17 void initialize() { 18 19 } 20 21}
Sample.fxml
1<?xml version="1.0" encoding="UTF-8"?> 2 3<?import javafx.scene.control.Button?> 4<?import javafx.scene.control.Label?> 5<?import javafx.scene.layout.AnchorPane?> 6<?import javafx.scene.layout.BorderPane?> 7<?import javafx.scene.text.Font?> 8 9 10<BorderPane prefHeight="400.0" prefWidth="400.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/15.0.1" fx:controller="application.SampleController"> 11 <center> 12 <AnchorPane prefHeight="725.0" prefWidth="386.0" BorderPane.alignment="CENTER"> 13 <children> 14 <Label layoutX="48.0" layoutY="189.0" prefHeight="50.0" prefWidth="160.0" text="Hello,World"> 15 <font> 16 <Font size="28.0" /> 17 </font> 18 </Label> 19 <Button layoutX="268.0" layoutY="202.0" mnemonicParsing="false" text="OK" /> 20 </children> 21 </AnchorPane> 22 </center> 23</BorderPane> 24
###質問
エラーの内容、意味、解決方法を知りたいです。
宜しくお願いします。
あなたの回答
tips
プレビュー