1

After finally getting the gui to run without problems whenever i click on a designated button the IDE (Eclipse) putting out a long massage with this error in its end.

Caused by: java.lang.NullPointerException
    at ui.IOTabController.handleSourceFolderPathSubmit(IOTabController.java:32)
    ... 62 more

Here is the IOTab.fxml (relevent part):

<AnchorPane fx:id="IOTab" minHeight="0.0" minWidth="0.0"
    prefHeight="282.0" prefWidth="676.0" xmlns="http://javafx.com/javafx/9"
    xmlns:fx="http://javafx.com/fxml/1" fx:controller="ui.IOTabController">
    <children>
        <Pane layoutX="12.0" layoutY="50.0" prefHeight="37.0" prefWidth="625.0">
            <children>
                <TextField id="sourceFolderFullPath" layoutX="167.0" layoutY="1.0" prefHeight="26.0"
                    prefWidth="391.0"/>
                <Button id="sourceFolderPathSubmit" layoutX="567.0" mnemonicParsing="false" text="Enter" 
                onAction="#handleSourceFolderPathSubmit"/>
                <Text layoutY="18.0" strokeType="OUTSIDE" strokeWidth="0.0"
                    text="Source folder's full path:" />
            </children>
        </Pane>
        ...
</AnchorPane>

Its controller IOTabController.java:

public class IOTabController implements Initializable{  // IOTab.fxml controller

    @FXML private MainController Main;
    // variables from fxml file to inject.
    @FXML private AnchorPane IOTab;
    @FXML private TextField sourceFolderFullPath;
    @FXML private Button sourceFolderPathSubmit;
    @FXML private TextField csvFileName;
    @FXML private Button csvFileNameSubmit;
    @FXML private Button deleteExistingData;
    @FXML private Button convertCsvToKml;

    @FXML
    protected void handleSourceFolderPathSubmit(ActionEvent event) { // handles path submit.
        if (sourceFolderFullPath.getText().isEmpty()) { // if empty field
            AlertHelper.showAlert(Alert.AlertType.ERROR, "Form Error!", "Please enter path.");
            return;
        }
        AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, "SUCCESS","Path inserted.");
    }

    // class for creating alerts.
    public static class AlertHelper {
        public static void showAlert(Alert.AlertType alertType, String title, String message) {
            Alert alert = new Alert(alertType);
            alert.setTitle(title);
            alert.setHeaderText(null);
            alert.setContentText(message);
            alert.showAndWait();
        }
    }

    @Override
    public void initialize(URL arg0, ResourceBundle arg1) {
        // TODO Auto-generated method stub

    }

}

The main controller:

public class MainController { // main.fxml controller.

    @FXML private IOTabController IOTabController;

    @FXML public void initialize() {
        System.out.println("Application started");
        IOTabController.initialize(null, null);
    }
}

The gui is running fine until I click on "sourceFolderPathSubmit" button which pops the warning above every click (no matter if i put text in the TextField or not). I cant seem to find what to add or remove to make the button work.

Zedler
  • 69
  • 1
  • 11
  • For the fields of your controller to be injected you need to use the `id` attribute of the `fx` namespace, i.e. ` – fabian Jan 01 '18 at 13:15

0 Answers0