javaFX应用程序错误:未指定资源 [英] javaFX application error: No resources specified

查看:166
本文介绍了javaFX应用程序错误:未指定资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是javaFX的新手,我正在尝试运行一个简单的应用程序。它的UI是用javaFX场景构建器创建的,Main类应该显示UI,而不是其他。

I'm new to javaFX and I'm trying to run a simple app. it's UI is created with javaFX scenebuilder and the Main class is supposed to display the UI, nothin else.

public class Main extends Application {

    public static void main(String[] args) {
        launch(Main.class, (String[])null);
    }

@Override
public void start(Stage primaryStage) {;
    try {
        AnchorPane root=(AnchorPane)FXMLLoader.load(Main.class.getResource("Main.fxml"));
        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.setTitle("Issue Tracking Lite Sample");
        primaryStage.show();
    } catch (IOException e) {System.err.println(e);}

    }


}

运行应用程序时出现此错误:

I got this error when running the app:

No resources specified.

/D:/workspace/FileSharing_ServerSide/bin/com/Shayan/FileSharing/Server/Main.fxml:16
  at javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:305)
at javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:197)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:588)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2430)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2136)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2742)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2721)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2707)
javafx.fxml.LoadException: No resources specified.

它表示该文件不存在,但它存在于该文件夹中,名称完全相同!它与代码在同一个包中。谁知道发生了什么事?!
提前感谢

It says that the file doesn't exists, but it exists in that folder with the exact same name! it's in the same package as the code is. anybody knows what's going on?! thanks in advance

推荐答案

JavaFX抛出异常 javafx.fxml.LoadException:没有资源指定。当FXMLLoader由于缺少资源而无法完全构建场景图时。

JavaFX throws the exception javafx.fxml.LoadException: No resources specified. when the FXMLLoader could not fully build the scene graph because of a missing resource.

这可能由于各种原因而发生。我遇到了以下因素:

This could happen for a variety reasons. I've encountered it because of the following:


  1. 加载fxml文件中指定的控制器时出错。

  2. fxml文件尝试引用 ResourceBundle 中的资源,但 FXMLLoader 没有 ResourceBundle 已正确配置。

  1. There was an error loading the controller specified in the fxml file.
  2. The fxml file tries to reference a resource in a ResourceBundle but the FXMLLoader did not have the ResourceBundle properly configured.

可能还有其他原因导致抛出此异常来自JavaFX,但根本原因是由于某种原因,FXMLLoader在尝试从fxml文件创建场景图时遇到异常。

There may be other reasons why this exception is thrown from within JavaFX, but the root cause is that for some reason or another, the FXMLLoader encountered an exception while trying to create the scene graph from the fxml file.

这篇关于javaFX应用程序错误:未指定资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆