Hello. Such a problem:

there is an fxml file with this code

<TextField fx:id="txtField" alignment="TOP_LEFT" onAction="#getNumberFromTF" prefHeight="25.0" prefWidth="54.0" /> 

and accordingly the controller of the following content: @FXML private TextField txtField;

 @FXML private void getNumberFromTF() { try { txtField.addActionListener((ae) -> MainApp.numberPage = Integer.parseInt(txtField.getText())); }catch (NumberFormatException e){ System.out.println(e); } } 

Why is fx: id highlighted in red in the fxml file? Hovering over fx: id with the cursor, IDEA shows the message: "Cannot set javafx.scene.control.TextField to field 'txtField'"

    1 answer 1

    The following should be written in your controller

     public TextField txtField; 

    or

     @Fxml private TextField txtField; 

    And most likely, you have not written so.

    • everything is written, that's just the point. Look more closely at the code in the line after the word "content:", the code for some reason did not get into the code block ... - Evgeni Gorohov
    • then give an example, as you declared in the controller, along with the imports - Andrew Bystrov
    • Plus, your getNumberFromTF method should take ActionEvent as parameters - Andrew Bystrov
    • The problem is solved, there was an import from the awt library, but it is necessary from javafx! - Evgeni Gorohov
    • And how then will the getNumberFromTF method look like if it should accept ActionEvent - Evgeni Gorohov