Textfield Null in Javafx

Asked

Viewed 390 times

0

I’m learning to develop in Javafx. I would like to be able to select an item in a tableView, when clicking a button, it opens a window with the details of the previously selected item. But I am facing the following error: textField is null when I try to assign the value of the object field to the text of textField.

controller.setCliente(cliente);
if (controller.getCliente() != null)
    controller.fillForm();

Down at the controller:

txtID.setText(cliente.getId().toString());
txtNome.setText(cliente.getNome());
// São vários campos

I have also tried to put in the initialize method, but without success. When I call txtID, it is null.

I appreciate the help of colleagues from now on.

  • 1

    It wouldn’t just be assigning a new instance of Textfield to him? txtID = new TextField();?

  • 1

    You can work with Tableview instance?

  • Gustavo Cinque, so I always have to instantiate all my components, as in Swing? I thought that in FXML this would be automatic...

  • Math, I can work with Tableview normally, it’s filled and I can capture the selected line normally. The error occurs when assigning the selected line (object field) to Textfield (as quoted in the above code).

  • No, you don’t have to instantiate your components. You should give an id for it in your fxml and use the annotation @FXML in your class to associate the id of fxml with the variable of your class. Question: How did you work with Tableview? It should be the same as it should be for Textfield.

  • It would be possible for you to post all the content of your control class that contains the Tableview and the control class of the new window, please?

  • If you are trying to show the selected item in the table, in another window( ie another class), you would have q, add the selected object in the class constructor. The window, is in the same class, or other???

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.