为什么可以';JavaFX是否找到我的.fxml控制器文件?
刚开始使用JavaFX,我有一个问题。 当我使用命令为什么可以';JavaFX是否找到我的.fxml控制器文件?,java,maven,javafx,gluon,Java,Maven,Javafx,Gluon,刚开始使用JavaFX,我有一个问题。 当我使用命令mvnjavafx:run从开始我的项目时,我得到了这个错误 Caused by: java.util.MissingResourceException: Can't find bundle for base name se.danielmartensson.controller.maincontroller, locale sv_SE at se.danielmartensson.Main.start(Main.java:42) 这
mvnjavafx:run
从开始我的项目时,我得到了这个错误
Caused by: java.util.MissingResourceException: Can't find bundle for base name se.danielmartensson.controller.maincontroller, locale sv_SE
at se.danielmartensson.Main.start(Main.java:42)
这是哪一行代码:
public class Main extends Application {
@Override
public void start(Stage stage) throws IOException {
AnchorPane root = FXMLLoader.load(Main.class.getResource("controller/maincontroller.fxml"), ResourceBundle.getBundle("se.danielmartensson.controller.maincontroller")); // <--- THIS
Scene scene = new Scene(root, 640, 480);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
但我还是有错误。我试图复制并重命名这些文件。但对我来说效果不太好
你能理解我在这里做错了什么吗?根据错误判断,它找不到资源包。如果您没有
se/danielmartensson/controller/maincontroller.properties
(也没有se/danielmartensson/controller/maincontroller\u sv\u se.properties
),则无法加载捆绑包。问题不在于加载您的maincontroller.fxml
,因为它在该点之前失败。@MarkRotteveel-AH。那么它们也很重要吗?@markrottveel不,它们不重要。您的代码加载一个资源包,这样资源包就必须存在,否则它会失败,并出现MissingResourceException
(在您的情况下就是这样)。否则,请使用fxmloader.load(URL)
而不是fxmloader.load(URL,ResourceBundle)
@markrottveel我删除了代码并将其更改为`ancorpane root=fxmloader.load(MainController.class.getResource(“MainController.fxml”);`现在它开始工作了。不知道为什么把它放在那里。
<plugin>
<groupId>com.gluonhq</groupId>
<artifactId>client-maven-plugin</artifactId>
<version>${client.maven.plugin.version}</version>
<configuration>
<target>${client.target}</target>
<mainClass>${main.class}</mainClass>
<bundlesList>
<list>se.danielmartensson.controller.maincontroller</list> Controller here
</bundlesList>
<reflectionList>
<list>se.danielmartensson.controller.MainController</list> Java file here
</reflectionList>
</configuration>
</plugin>