I'm new to FXML and can't figure out how to get entered text from a TextField. Below is my FMXL file from scenebuilder and my controller
FXML:
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="392.0" prefWidth="559.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="validator.FXMLDocumentController">
<children>
<GridPane layoutX="6.0" prefHeight="200.0" prefWidth="320.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="6.0" AnchorPane.rightAnchor="-6.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="181.0" minWidth="10.0" prefWidth="132.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="381.0" minWidth="10.0" prefWidth="348.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="138.0" minWidth="10.0" prefWidth="58.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>
<children>
<Button fx:id="button" onAction="#handleButtonAction" text="Validate" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<TextField id="XMLPath" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField id="XSDPath" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField id="OutputPath" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Xml Validation Tool" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="XML File Location:" GridPane.rowIndex="1" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="XSD File Location:" GridPane.rowIndex="2" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Output File Location:" GridPane.rowIndex="3" />
</children>
</GridPane>
</children>
</AnchorPane>
Controller:
public class FXMLDocumentController{
@FXML
private TextField XMLPath;
@FXML
private TextField XSDPath;
@FXML
private TextField OutputPath;
@FXML
private void handleButtonAction(ActionEvent event) {
System.out.println(XMLPath.getText());
System.out.println(XSDPath.getText());
System.out.println(OutputPath.getText());
}
}
When I click the button to retrieve the text, it gives me a null pointer errors. I feel like I'm missing something simple.