0

I am sorry if i asked the stupid question which might not apply in java fx.

I have the following fxml file

<AnchorPane  maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="294.0" prefWidth="354.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <Button fx:id="cancel" layoutX="199.0" layoutY="149.0" mnemonicParsing="false" text="Cancel" />
      <Button id="ok" fx:id="ok" layoutX="259.0" layoutY="149.0" mnemonicParsing="false" text="OK" />
      <TextField fx:id="field" layoutX="62.0" layoutY="120.0" prefHeight="26.0" prefWidth="229.0" />
   </children>
</AnchorPane>

Now i want to load that file. So i am trying to do the following.

Node parent = FXMLLoader.load(getClass().getResource("../layout/dialog.fxml"));
Button ok = (Button) parent.lookup("#id");

Here actually i want to access ok button by using lookUp method. But it says that ok button is null.

Note : i don't want to do this by using controller attribute fx:controller or @FXML annotation.

Is there any way that is possible to do so?

Ahad
  • 674
  • 1
  • 9
  • 22
  • Possible duplicate of [What's the difference between fx:id and id: in JavaFX?](https://stackoverflow.com/questions/23686325/whats-the-difference-between-fxid-and-id-in-javafx) – M. le Rutte May 06 '18 at 20:38
  • Your java code is fine. I think you are loading the wrong fxml file. – Umer Farooq May 07 '18 at 08:35
  • i am loading right file. But i don't know why it gives Null Pointer Exception. – Ahad May 07 '18 at 14:13

0 Answers0