Your structure is pretty unusual. It's more normal to structure an Application class, FXML file, and controller as shown in the tutorial.
As you have things set up, there is no connection between your controller class and the FXML. So the fields annotated @FXML
never get initialized.
The way this is intended to work, is that the FXMLLoader
's load(...)
method will parse the FXML file. If there is a controller set on the loader, then any elements with a fx:id
attribute defined will be injected into matching @FXML
annotated fields in the controller.
There are basically two ways of setting a controller on the FXMLLoader
. The first is to have a fx:controller
attribute defined on the root element of the FXML file. This will cause the FXML loader to create a new instance of the specified class, and use that as its controller. Note this won't work in your case, because you want the controller to be the Prove
instance you have already created, not a new instance of the Prove
class.
The second way is to create an FXMLLoader
instance (instead of relying on the static
FXMLLoader.load(URL)
method you are currently using), and call setController(...)
on that instance. So (I think) uncommenting the
//fxmlLoader.setController(this);
line will get this to work.
You may need to separate the declarations of the fields too, i.e.:
@FXML
private Label StartFomulars ;
@FXML
private Label GoalFomular;
(It might work without that change, I've never tried it the way you have it.)
You should probably also take out the try {...} catch (...) {...}
structure in the constructor for Prove
(since you declare it throws IOException
anyway), or at least do something in the catch
block. Right now if an exception occurs loading the FXML you won't know about it, and you will just plough ahead and try and set the text of the label.