JavaFX application error: no resource specified

I'm new to JavaFX and I'm trying to run a simple application Its UI is created by JavaFX scene builder, and the main class should display the UI, not others

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);}

    }


}

This error occurred while running the application:

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 the file does not exist, but it exists in a folder with exactly the same name! It is in the same package as the code Who knows what happened?! Thank you in advance

Solution

JavaFX throws an exception fxml. Loadexception: no resource specified When fxmlloader cannot fully build the scene diagram due to lack of resources

This can happen for various reasons I encountered it for the following reasons:

>Error loading controller specified in fxml file. > The fxml file attempted to reference a resource in a resourcebundle, but the fxmlloader did not properly configure the resourcebundle

There may be other reasons for throwing this exception in JavaFX, but the root cause is that for some reason, fxmlloader encountered an exception when trying to create a scene diagram from an fxml file

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>