javafx : javafx.scene.layout.AnchorPane cannot be cast to javafx.scene.layout.BorderPane

后端 未结 3 646
闹比i
闹比i 2021-01-15 07:55

hey guys i am knew to javafx and i am trying to cast a BorderPane to an anchronPane, meanwhile an error occured and i don t know what to do, i was following a tutorial so pl

3条回答
  •  日久生厌
    2021-01-15 08:43

    I was following the same tutorial as well, and encountered the same issue.

    In my case, while creating the RootLayout FXML, I erroneously selected AnchorPane as the root element instead of BorderPane. So, in the initRootLayout() method, it tried to Cast AnchorPane object to BorderPane object. And as mentioned in the previous comment that, AnchorPane and BorderPane extend Pane, it is not possible to cast them with each other!

    Thus, if you select BorderPane as the root element for RootLayout.fxml, it correctly casts the object to BorderPane. Thus, now I am wondering, if this casting is even required?

    I hope your issue is resolved by now. This might be helpful to someone else who encounters this problem!

提交回复
热议问题