onAction event handles is marked as error in FXML [message #1474484] |
Sat, 15 November 2014 13:07  |
Eclipse User |
|
|
|
I have an FXML file that includes <Button> tags generated by Scene Builder. The name of the controller class is properly set in FXML and has the following code:
public class CalculatorController {
public void buttonClickHandler(ActionEvent evt){
Button clickedButton = (Button) evt.getTarget();
System.out.println("You clicked on " + clickedButton.getText());
}
}
When I add onAction="#buttonClickHandler" to FXML Button controls the program works fine, but Eclipse marks it red displaying the "error" as "The CalculatorController has no event slot 'buttonClickHandler'". The sample FXML button is shown next:
<Button onAction="#buttonClickHandler" mnemonicParsing="false" prefHeight="37.0" prefWidth="132.0" text="MC">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</Button>
|
|
|
|
|
Re: onAction event handles is marked as error in FXML [message #1691457 is a reply to message #1474647] |
Tue, 07 April 2015 11:44  |
Eclipse User |
|
|
|
Hi Thomas,
I am facing the same problem. I have three packages: Application,controller and GUI.The GUI has multiple .fxml files each for 1 tab and there is one more .fxml file which is Prime.fxml which will import all the other .fxml files.
All .fxml has one controller class each in controller package.I have two buttons in one of the .fxml files with which i have attached one method each and i have implemented them in one of the controller file pertaining to that .fxml(this .fxml is not Prime.fxml).And when i run the app i get this exception:
javafx.fxml.LoadException: Error resolving onAction='#setTestLocation', either the event handler is not in the Namespace or there is an error in the script.
And here in the below code i am getting compilation error for the method names of the buttons.
<Button fx:id="btn1" layoutX="529.0" layoutY="351.0" mnemonicParsing="false" onAction="#setTestLocation" text="Browse" />
<Button fx:id="btn2" layoutX="529.0" layoutY="409.0" mnemonicParsing="false" onAction="#setConfigFileLocation" text="Browse" />
Please help,its been two days.
|
|
|
Powered by
FUDForum. Page generated in 0.03826 seconds