Saturday, February 22, 2014

[Solved] Error: Controller is not defined on root component

If you happen to come across this error in you FXML file and you find out that you did mentioned fx:controller tag in your FXML file and its RED underline, then it means that your Netbeans needs update.

When you install Netbeans initally, it will show you some updates after connecting to internet. If you somehow ignore them or failed to update then these errors will show up. Remember that these errors will only show up when you save the project using Scene Builder. Scene Builder has latest update of JavaFx package than Netbeans. Upon updation, both will have same versions.

Here is the code that you will find in FXML file using Netbeans IDE :

...xmlns:fx="http://javafx.com/fxml" fx:controller="netbeansjavafxtest.FXMLDocumentController">

whereas after saving the file using Scene Builder, the above line will change to :

...xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2"

fx:controller="netbeansjavafxtest.FXMLDocumentController">

After updating the Netbeans, there will be no more Red Underlines on the above code. Updating Netbeans is quite simple.Easy Peasy!

6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. already i work on netbeans 8.0.2 and using scene builer 2.0
    but still error ocur .
    in FXML file when i performe action on button onAction="#handleActiozn" it show error
    controller is not define on rootcomponents so help me

    ReplyDelete
  4. Right statement is onAction= "handleAction"

    ReplyDelete
  5. If you are on netbeans with scene builder maybe checking controller in library and assign the controller class.

    ReplyDelete
  6. Just right click and select make controller

    ReplyDelete