简体   繁体   English

无法识别Java FX控制器

[英]Java FX Controller not recognized

Today when I was working on Windows, there was no problem at all. 今天,当我在Windows上工作时,完全没有问题。 After transferring to my Mac at home, trouble started. 在家里转移到我的Mac后,麻烦开始了。

I have the following path in the FXML (BorderPane): 我在FXML(BorderPane)中具有以下路径:

fx:controller="application.controllers.DashboardController"

The directory structure looks like this: 目录结构如下所示:

在此处输入图片说明

Eclipse keeps saying that 'the controller has no field XXX'. Eclipse一直说“控制器没有字段XXX”。

在此处输入图片说明

It seems to me quite clear that they are there! 在我看来,他们在那里很清楚!

在此处输入图片说明

The interface gets properly loaded when run, I'm quite sure the path is correct. 接口在运行时会正确加载,我很确定路径是正确的。
However, the controller is not recognised, and 'test' doesn't get printed. 但是,无法识别控制器,并且不会打印“ test”。

Any hints? 有什么提示吗?

FXML loader and IDEs (eg Eclipse) use reflection to retrieve information about the controller. FXML加载器和IDE(例如Eclipse)使用反射来获取有关控制器的信息。 In your case you seem to have an inner class PleaseProvideControllerClassName where the annotated fields are. 在您的情况下,您似乎有一个内部类PleaseProvideControllerClassName ,其中带注释的字段位于其中。 Hence, from reflection's perspective the DashboardController class itself does not contain any fields at all. 因此,从反射的角度来看, DashboardController类本身根本不包含任何字段。

It's worth noting that nested classes should not be used in controllers. 值得注意的是,嵌套类不应在控制器中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM