无法使用 JAVAFX FXML 文件启动应用程序

Cant launch application using JAVAFX FXML file

我正在尝试从主 class (MAAWB) 启动 IntLogin window;但是,我似乎无法启动它。我的闪屏启动没有问题。我 运行 一个没有问题的调试,直到它到达启动序列然后它踢回一个无法识别的错误。我在下面包含了主要文件、fxml 和控制器文件。我在这里遗漏了什么或做错了什么让我头疼?另外,如果有人知道我该如何将启动画面设置为计时器?

主要

package javafxswingapplication3;

import javafx.application.Application;
import javafx.application.Preloader;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;


public class MAAWB extends Application {

@Override
public void start(Stage primaryStage) {
    Parent root;
    try {
    root = FXMLLoader.load(getClass().getResource("Intlogin.fxml"));
    Stage stage = new Stage();
    stage.setTitle("initial login");
    stage.setScene(new Scene(root, 222, 484));
   stage.show();

} catch(Exception e){
    e.printStackTrace();
    }
}

public static void main(String[] args) {
    Preloader.launch(MAAWBPreloader.class, args);
    Application.launch(MAAWB.class, args);



}

}

fxml

<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.effect.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" prefHeight="222.0" prefWidth="484.0"     xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"     fx:controller="javafxswingapplication3.IntloginController">
   <children>
  <TextField layoutX="173.0" layoutY="50.0" />
  <TextField fx:id="username" editable="false" layoutX="173.0" layoutY="90.0" />
  <ChoiceBox layoutX="173.0" layoutY="130.0" prefHeight="31.0" prefWidth="187.0" />
  <Label layoutX="91.0" layoutY="55.0" text="Installation" />
  <Label layoutX="94.0" layoutY="95.0" text="Username" />
  <Label layoutX="58.0" layoutY="135.0" text="Functional Area" />
  <Button cancelButton="true" layoutX="400.0" layoutY="182.0"     mnemonicParsing="false" text="Cancel" />
  <Button layoutX="327.0" layoutY="182.0" mnemonicParsing="false" text="Submit" />
</children>
</AnchorPane>

控制器

package javafxswingapplication3;

import java.net.URL;
import java.util.ResourceBundle;
import java.util.Properties;
import static javafx.application.ConditionalFeature.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;

public class IntloginController implements Initializable {

private TextField username;

@Override
public void initialize(URL url, ResourceBundle rb) {
    final String UN = System.getProperty("user.name");

    username.setText(UN);
}    

}

错误

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
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 javafxswingapplication3.MAAWB.start(MAAWB.java:31)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication12(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait5(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null3(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater4(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$null8(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at javafxswingapplication3.IntloginController.initialize(IntloginController.java:28)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)

注释用户名定义@FXML

@FXML
private TextField username;

这将通过 fx:id="username".

将控制器中定义的 TextField 与 FXML 中定义的文本字段相关联