我试图按Quit
MenuItem
按Exit
应用程序的方法。JavaFX不能在MenuItem上使用onAction
我有以下方法:
@FXML
public void doExit(ActionEvent event) {
Platform.exit();
System.exit(0);
}
我收到此错误:
javafx.fxml.LoadException: Error resolving onAction='doExit', either the event handler is not in the Namespace or there is an error in the script.
project/build/resources/main/Player.fxml:21
线Player.fxml
21是这样的:
<MenuItem mnemonicParsing="false" onAction="doExit" text="Quit" />
我试图删除/添加@FXML
表示法,该方法未定义为static
所以它应该工作,我有ActionEvent
你有FX:控制器属性,在FXML文件? –
不,但我不明白为什么现在需要?我试图将其设置为crassname:Player,但它不起作用,没有找到它。 –
需要解析“#doExit”,否则它甚至不会猜测在哪里查找;)。为Player提供完整的包路径,如fx:controller =“path.to.my.Player” –