当应用程序初始化时,FXMLLoader.constructLoadException被阻止 [英] FXMLLoader.constructLoadException occuered when app gets initialize

查看:298
本文介绍了当应用程序初始化时,FXMLLoader.constructLoadException被阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了联系人管理器应用程序,当我尝试运行它时,我在java.security.AccessController上遇到以下错误

I have build contact manager app and When I try to run it I got following error

at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at `enter code here`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$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
    at addressapp.PersonOverviewController.initialize(PersonOverviewController.java:52)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    ... 13 more

之后,我在 initialize()块和<$ c中搜索停止了应用程序的位置$ c> setCellValueFactory() of我的表视图列。这是我的控制器代码。请告诉我这段代码的问题是什么?

After that I searched where there the application stopped stopped within the initialize() block and setCellValueFactory() of my table view column. This is my controller code. Please tell me what is the matter of this code?

控制器

package addressapp;

import addressapp.Model.Person;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;


public class PersonOverviewController implements Initializable {

    @FXML
    private TableView<Person> personTable;

    @FXML
    private TableColumn<Person, String> firstNameColumn;

    @FXML
    private TableColumn<Person, String> lastNameColumn;

    @FXML
    private Label firstNameLabel;

    @FXML
    private Label lastNameLabel;
    @FXML
    private Label streetLabel;
    @FXML
    private Label postalCodeLabel;
    @FXML
    private Label cityLabel;
    @FXML
    private Label birthdayLabel;

    private AddressApp AddressApp;

    public PersonOverviewController() {
    }



    @Override
    public void initialize(URL url, ResourceBundle rb) {

        firstNameColumn.setCellValueFactory(new PropertyValueFactory<>("firstName"));

        lastNameColumn.setCellValueFactory(new PropertyValueFactory<>("lastName"));

          }

    public void setMainApp(AddressApp mainApp) {

        this.AddressApp = mainApp;

        personTable.setItems(mainApp.getPersonData());
    }

}

这里我的FXML

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" prefHeight="484.0" prefWidth="584.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="addressapp.PersonOverviewController">
    <children>
        <Label fx:id="label" layoutX="126" layoutY="120" minHeight="16" minWidth="69" />
      <SplitPane layoutX="-2.0" prefHeight="484.0" prefWidth="584.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <items>
          <AnchorPane prefHeight="300.0" prefWidth="600.0">
               <children>
                  <SplitPane dividerPositions="0.29797979797979796" layoutX="14.0" prefHeight="482.0" prefWidth="582.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                    <items>
                      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
                           <children>
                              <TableView id="personTable" layoutX="-7.0" layoutY="40.0" prefHeight="480.0" prefWidth="170.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                                <columns>
                                  <TableColumn id="firstNameColumn" prefWidth="75.0" text="First Name" />
                                  <TableColumn id="lastNameColumn" prefWidth="83.0" text="Last Name" />
                                </columns>
                                 <columnResizePolicy>

                                 </columnResizePolicy>
                              </TableView>
                           </children>
                        </AnchorPane>
                      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
                           <children>
                              <Label layoutX="25.0" layoutY="25.0" text="Person Details" AnchorPane.leftAnchor="5.0" AnchorPane.topAnchor="5.0" />
                              <GridPane layoutX="14.0" layoutY="42.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="40.0">
                                <columnConstraints>
                                  <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                                  <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                                </columnConstraints>
                                <rowConstraints>
                                  <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                                  <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                                  <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                                    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                                    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                                    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                                </rowConstraints>
                                 <children>
                                    <Label text="First Name" />
                                    <Label text="Last Name" GridPane.rowIndex="1" />
                                    <Label text="Street" GridPane.rowIndex="2" />
                                    <Label text="City" GridPane.rowIndex="3" />
                                    <Label text="Postal Code" GridPane.rowIndex="4" />
                                    <Label text="Birthday" GridPane.rowIndex="5" />
                                    <Label id="firstNameLabel" text="Label" GridPane.columnIndex="1" />
                                    <Label id="lastNameLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1" />
                                    <Label id="streetLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" />
                                    <Label id="postalCodeLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3" />
                                    <Label id="cityLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="4" />
                                    <Label id="birthdayLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="5" />
                                 </children>
                              </GridPane>
                              <Button layoutX="338.0" layoutY="441.0" mnemonicParsing="false" text="Delete" />
                              <Button layoutX="286.0" layoutY="441.0" mnemonicParsing="false" text="Edit.." />
                              <Button layoutX="232.0" layoutY="441.0" mnemonicParsing="false" text="New.." AnchorPane.rightAnchor="126.0" />
                           </children>
                        </AnchorPane>
                    </items>
                  </SplitPane>
               </children></AnchorPane>
        </items>
      </SplitPane>
    </children>
</AnchorPane>


推荐答案

您的FXML文件使用 id 属性,而不是所有控件上的 fx:id 属性。因此, @FXML - 注释字段均未被 FXMLLoader 初始化。

Your FXML file is using an id attribute, instead of the fx:id attribute on all the controls. Consequently, none of the @FXML-annotated fields are initialized by the FXMLLoader.

你需要

<TableColumn fx:id="firstNameColumn" prefWidth="75.0" text="First Name" />
<TableColumn fx:id="lastNameColumn" prefWidth="83.0" text="Last Name" />

和所有其他控件类似。

这篇关于当应用程序初始化时,FXMLLoader.constructLoadException被阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆