私はプロジェクトに取り組んでおり、ユーザーがアイテムを追加したり削除したりできるメニューを用意したいと考えています。私はあなたのメニューオブジェクトでgetItemsを使用すると言うjavaドキュメントを見てきましたが、これは実行時にnullポイントエラーを与えています "原因:java.lang.NullPointerException at app.Main_Controller.PopulateModelBarAdd(Main_Controller.java:257)"JavaFX FXML変更リスト
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.91" xmlns:fx="http://javafx.com/fxml/1" fx:controller="app.Main_Controller">
<children>
<VBox layoutX="-1.0" layoutY="39.0" prefHeight="361.0" prefWidth="270.0">
<children>
<HBox prefHeight="37.0" prefWidth="270.0">
<children>
<TextField fx:id="VarientAdminPanelText" promptText="Varient" />
<Button fx:id="RemoveVarAdminPanel" mnemonicParsing="false" text="Remove" />
<Button fx:id="AddVarAdminPanel" mnemonicParsing="false" text="Add " onAction= "#PopulateModelBarAdd"/>
</children>
</HBox>
<HBox prefHeight="33.0" prefWidth="270.0">
<children>
<TextField fx:id="XCordAdminPanel" promptText="X codinate" />
<TextField fx:id="YCordAdminPanel" promptText="Y Cordinate" />
<TextField fx:id="ZCordAdminPanel" promptText="Z Cordinate" />
</children>
</HBox>
<HBox prefHeight="262.0" prefWidth="270.0">
<children>
<Button fx:id="AddCordAdminPanel" mnemonicParsing="false" prefHeight="25.0" prefWidth="135.0" text="Add" />
<Button fx:id="RemoveCordAdminPanel" mnemonicParsing="false" prefHeight="25.0" prefWidth="139.0" text="Remove" />
</children>
</HBox>
<Button fx:id="AdminBack" mnemonicParsing="false" onAction="#HandelAdminVeiwMain" text="Back To Main Veiw" />
</children>
</VBox>
<HBox layoutX="4.0" prefHeight="32.0" prefWidth="600.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Admin Panel">
<font>
<Font name="Calibri" size="34.0" />
</font>
</Text>
</children>
</HBox>
<VBox layoutX="279.0" prefHeight="400.0" prefWidth="321.0" />
</children>
</AnchorPane>
メニューであるFXMLファイル:
<GridPane hgap="14.0" maxHeight="+Infinity" maxWidth="+Infinity" minHeight="-Infinity" minWidth="-Infinity" vgap="20.0" xmlns="http://javafx.com/javafx/8.0.91" xmlns:fx="http://javafx.com/fxml/1" fx:controller="app.Main_Controller">
<children>
<ImageView fitHeight="61.0" fitWidth="60.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="0" GridPane.halignment="CENTER" GridPane.rowIndex="0" GridPane.valignment="TOP">
<image>
<!-- place holder -->
</image>
</ImageView>
<VBox maxHeight="+Infinity" maxWidth="+Infinity" minHeight="-Infinity" prefWidth="400.0" spacing="7.0" GridPane.columnIndex="1" GridPane.rowIndex="0">
<children>
<Label fx:id="messageLabel" text="Remove from Buffer" textAlignment="LEFT" wrapText="true">
<font>
<Font name="System Bold" size="13.0" />
</font>
</Label>
<Label fx:id="detailsLabel" textAlignment="LEFT" wrapText="true">
<font>
<Font size="12.0" />
</font>
</Label>
<SplitMenuButton fx:id="RemoveVarMenu" mnemonicParsing="false" prefHeight="25.0" prefWidth="96.0" text="Model">
<items>
<Menu fx:id="test" mnemonicParsing="false" text="Unspecified Menu">
<items>
<MenuItem mnemonicParsing="false" text="Action 1" />
</items>
</Menu>
<MenuItem mnemonicParsing="false" text="Alasdair" />
</items></SplitMenuButton>
</children>
</VBox>
<HBox maxHeight="-Infinity" maxWidth="+Infinity" minHeight="-Infinity" minWidth="-Infinity" GridPane.columnIndex="1" GridPane.rowIndex="1">
<children>
<HBox fx:id="actionParent" alignment="CENTER">
<HBox.margin>
<Insets />
</HBox.margin>
</HBox>
<Pane maxWidth="+Infinity" HBox.hgrow="ALWAYS">
<children>
<TextField fx:id="RemoveNumTextFeild" prefHeight="25.0" prefWidth="96.0" promptText="num to remove" />
</children></Pane>
<Button fx:id="RemoveCancelButton" cancelButton="true" minWidth="80.0" mnemonicParsing="false" onAction="#HandelRemoveMain" text="Cancel" HBox.hgrow="NEVER">
<HBox.margin>
<Insets />
</HBox.margin>
</Button>
<HBox fx:id="okParent" alignment="CENTER">
<children>
<Button fx:id="okButtonRemove" minWidth="80.0" mnemonicParsing="false" onAction="#HandelRemoveToBufferPopup" text="Ok" HBox.hgrow="NEVER">
<HBox.margin>
<Insets left="14.0" />
</HBox.margin>
</Button>
</children>
</HBox>
</children>
</HBox>
</children>
<columnConstraints>
<ColumnConstraints hgrow="NEVER" maxWidth="55.0" minWidth="-Infinity" prefWidth="0.0" />
<ColumnConstraints halignment="CENTER" hgrow="ALWAYS" maxWidth="Infinity" minWidth="-Infinity" prefWidth="460.0" />
</columnConstraints>
<padding>
<Insets bottom="14.0" left="14.0" right="14.0" top="14.0" />
</padding>
<rowConstraints>
<RowConstraints maxHeight="+Infinity" minHeight="-Infinity" valignment="CENTER" vgrow="ALWAYS" />
<RowConstraints maxHeight="-Infinity" minHeight="-Infinity" vgrow="NEVER" />
</rowConstraints>
</GridPane>
コントローラで使用されるコードは
@FXML
public Menu test;
public TextField VarientAdminPanelText;
public void PopulateModelBarAdd(){
MenuItem item = new MenuItem(VarientAdminPanelText.getText());
System.out.println(test.getItems());
test.getItems().addAll(item);
}
ティのように見えますあなたが外でそれを宣言した場合、テストのためにid要素:Sは、それが
public Menu test;
@FXML //define FXML for VarientAdminPanelText
public TextField VarientAdminPanelText;
public void PopulateModelBarAdd(){
MenuItem item = new MenuItem(VarientAdminPanelText.getText());
System.out.println(test.getItems());
test.getItems().addAll(item);
}
にFXML
タグがどこに変わるのかを変更するのはなぜですか? – ajjohnson
メニューはdif FXMLファイルで初期化されています – ajjohnson
私はあなたに「\t」というメッセージが表示されませんでした。 –