Error loading fxml file in a JavaFX project


I have been working on a desktop application, where I need to use JavaFX. I have created an fxml file in a JavaFX project on eclipse. I build the scene in scene builder.when I am trying to run the main Java file, the changes which are made using scene builder on the fxml file are not getting reflected on the main window.and the screen is displayed blank. here is my code.

public class Main extends Application {
public void start(Stage primaryStage) {
    try {
        AnchorPane  root = new AnchorPane();

        Scene scene = new Scene(root,400,400,Color.BLACK);
        primaryStage.setTitle("FXML Welcome");

    } catch(Exception e) {

public static void main(String[] args) {

And this is my sample.fxml file code:

<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<?scenebuilder-background-color 0x00ffa3ff?>

<AnchorPane prefHeight="379.0" prefWidth="549.0001220703125" xmlns:fx="" xmlns="">

<Button layoutX="219.0" layoutY="156.0" mnemonicParsing="false" text="hello" />

The error I got was:

     WARNING: com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged Resource "/F:/eclipse_progs/examplefx/bin/application/sample.fxml" not found.

But the location in the error specified contains the file it is referring to. Can anyone explain what might be the reason with the error. Is it with the code or is with the issues of plugin?

3/28/2014 12:03:25 PM

Accepted Answer

In JavaFX, if you want to load the a fxml file, then use the FXMLLoader as,


To load stylesheet use as.


In your code, you are adding the fxml file in the stylesheets list of the scene which is wrong. Try using FXMLLoader as said above to load your fxml file.

Refer docs:

3/20/2014 1:00:17 PM

Try this start method and place your directory application/<NAME>.fxml in the same directory where your Main.class is fxml files getting loaded with the static FXMLLoader.load() method with getStylesheets.add(...) you can add .css files to your scene.

    public void start(Stage primaryStage) throws IOException {

        Parent parent = FXMLLoader.load(getClass().getResource("application/demo.fxml"));
        Scene scene = new Scene(parent);
        primaryStage.setTitle("Hello World!");

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow