JavaFX在.fxml文件中抛出LoadException

时间:2016-11-05 15:31:22

标签: java intellij-idea javafx fxml

我是Java新手,但我有PHP和Javascript背景。我正在尝试构建一个具有基本登录,数据处理和注销功能的交互式JavaFX应用程序 - 非常直接。

目前我偶然发现了一个我真不理解的问题。我在两个不同的环境中发展 - 在家里和工作中。我在家里开始我的项目,没有安装JDK和IntelliJ以及设置项目配置的问题。我在我的工作计算机上执行相同的步骤(OS X - 与家用计算机相同)但我无法从IntelliJ运行该应用程序。

FXML文件:

<?xml version="1.0" encoding="UTF-8"?>
<?language javascript?>
<?import java.net.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>


<GridPane fx:controller="carmanager.login.LoginController" xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10" styleClass="root">
    <padding>
        <Insets top="25" right="25" bottom="10" left="25"/>
    </padding>
    <stylesheets>
        <URL value="@../../fxml_styles.css" />
    </stylesheets>
    <fx:script source="../../fxml_scripts.js"></fx:script>
    <!--<gridLinesVisible>true</gridLinesVisible>-->

    <Text id="welcome-text" text="Welcome"
          GridPane.columnIndex="0" GridPane.rowIndex="0"
          GridPane.columnSpan="2"/>

    <Label text="User Name:"
           GridPane.columnIndex="0" GridPane.rowIndex="1"/>

    <TextField fx:id="userNameField"
            GridPane.columnIndex="1" GridPane.rowIndex="1"/>

    <Label text="Password:"
           GridPane.columnIndex="0" GridPane.rowIndex="2"/>

    <PasswordField fx:id="passwordField"
                   GridPane.columnIndex="1" GridPane.rowIndex="2"/>

    <HBox spacing="10" alignment="bottom_right"
          GridPane.columnIndex="1" GridPane.rowIndex="4">

        <Button text="Sign In"
                onAction="#tryLogin"/>
    </HBox>

    <HBox spacing="10" alignment="bottom_right"
          GridPane.columnIndex="1" GridPane.rowIndex="5">
        <Text fx:id="actiontarget"
              GridPane.columnIndex="1" GridPane.rowIndex="5"/>
    </HBox>

</GridPane>

主要课程:

package carmanager;


import carmanager.login.LoginController;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application{

    @Override
    public void start(Stage primaryStage) throws Exception {
        Parent root = FXMLLoader.load(LoginController.class.getResource("login.fxml"));
        primaryStage.setTitle("Car manager - Welcome");
        primaryStage.setScene(new Scene(root, 400, 375));
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

错误:

    Exception in Application start method
Exception in thread "main" 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$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException: 
/Users/erik/Projects/car-manager-i200/out/carmanager/login/login.fxml:22

    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 carmanager.Main.start(Main.java:15)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:262)
    at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:54)
    at javafx.fxml.FXMLLoader$Element.applyProperty(FXMLLoader.java:512)
    at javafx.fxml.FXMLLoader$Element.processValue(FXMLLoader.java:363)
    at javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:325)
    at javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:235)
    at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:767)
    at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
    ... 14 more
Caused by: 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 sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    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.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:258)
    ... 22 more
Caused by: java.lang.NullPointerException
    at com.sun.javafx.font.MacFontFinder.populateFontFileNameMap(MacFontFinder.java:99)
    at com.sun.javafx.font.PrismFontFactory.getFullNameToFileMap(PrismFontFactory.java:1740)
    at com.sun.javafx.font.PrismFontFactory.getFontResource(PrismFontFactory.java:469)
    at com.sun.javafx.font.LogicalFont.getSlot0Resource(LogicalFont.java:194)
    at com.sun.javafx.font.LogicalFont.getDefaultAAMode(LogicalFont.java:409)
    at com.sun.javafx.font.LogicalFont.getStrike(LogicalFont.java:413)
    at com.sun.javafx.font.PrismFont.getStrike(PrismFont.java:73)
    at com.sun.javafx.text.PrismTextLayout.setContent(PrismTextLayout.java:138)
    at javafx.scene.text.Text.getTextLayout(Text.java:229)
    at javafx.scene.text.Text.needsFullTextLayout(Text.java:184)
    at javafx.scene.text.Text.access$200(Text.java:95)
    at javafx.scene.text.Text$2.invalidated(Text.java:389)
    at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:109)
    at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:144)
    at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:49)
    at javafx.scene.text.Text.setText(Text.java:370)
    ... 33 more

Process finished with exit code 1

如果我删除嵌套在FXML文件中的GridPane块内的所有内容,代码将编译并运行,没有任何问题。我认为这可能与我的工作计算机上的配置有关,因为代码在我的家用计算机上运行没有任何问题。问题是,我如何确切地找出问题所在?

0 个答案:

没有答案