I\'m new to javaFx,and I have found only within the @fxml function and initialize function the @fxml field not be null otherwise the @fxml field will always be null,is it true?
You can specify the controller in the FXML file. The FXMLLoader will initialize the variables in the controller. In that case there is not problem with your code. It is good practice to separate the controller from the main class.