Eclipseを使ってJavaFXの勉強しています。
以下のコードを組み合わせて実行しても、何も表示されないです。
FxmlSmpl.javaとfxmlSmpl.fxmlは同じpackage applicationにあります。
"fxmlSmpl.fxml"を絶対パスにしても変わりませんでした。
FXMLLoader(getClass().getResource("fxmlSmpl.fxml");
HBox root = fxml.load();
あたりにエラーがあるみたいですが、よくわかりません。
教えていただけませんか。
よろしくお願いいたします。
//FxmlSmpl.java package application; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class FxmlSmpl extends Application { @Override public void start(Stage stage) throws Exception { stage.setTitle("FxmlSmpl"); FXMLLoader fxml = new FXMLLoader(getClass().getResource("fxmlSmpl.fxml")); HBox root = fxml.load(); Scene scene = new Scene(root); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } } //fxmlSmpl.fxml <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.cotrol.*?> <?import javafx.scene.layout.*?> <HBox> <children> <Label text="ラベル" prefWidht="80.0" /> </children> </HBox> // 以下はコンソールに出ているエラーの内容です。 Exception in Application start method java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) Caused by: java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.IllegalStateException: Location is not set. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) at application.FxmlSmpl.start(FxmlSmpl.java:18) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177) ... 1 more Exception running application application.FxmlSmpl
読み込み対象のfxmlファイルはfxmlBMI.xmlとfxmlSmpl.xmlどちらが正しいのですか?、正しいファイル名に質問文を編集して統一してくださいな。

すみませんでした。次のBMIのプログラムでも同じような原因で止まっていて、苦戦していてこんがらがってしまいました。

質問の仕方が悪かったので修正しました。

回答1件
あなたの回答
tips
プレビュー