我目前正在將我的匆忙製作的JavaFX應用程序佈局從Java遷移到FXML,所以我可以單獨擔心樣式,視圖,控制器和模型,但我似乎無法運行簡單你好世界應用程序。爲什麼我無法啓動這個簡單的FXML Hello World應用程序?
我得到以下錯誤:
Exception in Application start method
java.lang.reflect.InvocationTargetException
這裏是View.fxml文件
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml" fx:controller="calend.ae.Controller">
<Label text="I love bacon"/>
<Button text="Submit"/>
</VBox>
和主類
package calend.ae;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Model extends Application {
public static void main(String[]args) {
launch(args);
}
@Override
public void start(Stage stg) throws Exception{
Parent tabs = FXMLLoader.load(getClass().getResource("View.fxml"));
stg.setTitle("Hello World");
stg.setScene(new Scene(tabs, 450, 250));
stg.show();
}
}
你可以找到源全部代碼here。我只是想知道爲什麼它不跑,這裏上下文是實際application
以下是完整的堆棧跟蹤:使用maven或螞蟻
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at calend.ae.Model.start(Model.java:17)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
... 1 more
Exception running application calend.ae.Model
Picked up _JAVA_OPTIONS: -Xmx512M
安置自己的代碼在這裏不是在外部網站 – Reimeus
還發布完整的堆棧跟蹤。 –
@James_D貼,謝謝。 – Zunon