javafx.fxml.LoadException occurs while loading FXML

1k views Asked by At

I am trying to create a very simple VBox with a black background. Thats all. Nothing else. I am using FXML to describe my VBox.

sample.fxml:

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.VBox?>

<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="sample.Controller" alignment="CENTER" background="#000000ff">
</VBox>   

Controller.java:

package sample;

public class Controller {  
    // No code written. Not required.
}  

Main.java:

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;


/* Code auto generated by IDEA IDE. */
public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Adi's login app");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    } 


    public static void main(String[] args) {
        launch(args);
    }
}  

I am using IDEA IntelliJ IDE. And I am getting the following error:

Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
 at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
 at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImpl.java:182)
 at com.sun.javafx.application.LauncherImpl$$Lambda$2/51228289.run(Unknown Source)
 at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException: 
/Users/aditya/Desktop/workspace/Java/LoginApp/out/production/LoginApp/sample/sample.fxml:5

 at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2605)
 at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2583)
 at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
 at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3218)
 at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
 at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
 at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3128)
 at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3108)
 at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3101)
 at sample.Main.start(Main.java:13)
 at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
 at com.sun.javafx.application.LauncherImpl$$Lambda$53/87719178.run(Unknown Source)
 at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
 at com.sun.javafx.application.PlatformImpl$$Lambda$49/2001689116.run(Unknown Source)
 at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
 at com.sun.javafx.application.PlatformImpl$$Lambda$51/779320874.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
 at com.sun.javafx.application.PlatformImpl$$Lambda$50/1474675095.run(Unknown Source)
 at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: java.lang.IllegalArgumentException: Unable to coerce #000000ff to class javafx.scene.layout.Background.
 at com.sun.javafx.fxml.BeanAdapter.coerce(BeanAdapter.java:495)
 at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:258)
 at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:54)
 at javafx.fxml.FXMLLoader$Element.applyProperty(FXMLLoader.java:508)
 at javafx.fxml.FXMLLoader$Element.processValue(FXMLLoader.java:359)
 at javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:321)
 at javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:231)
 at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:763)
 at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2827)
 at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2536)
 ... 18 more

Why is this happening? Please let me know if I am making any mistake or if I am missing out anything.

1

There are 1 answers

0
NFRiaCowboy On

Is nothing to do with Intellij, I also had this issue. I was compiling with Java 1.8, I changed to 1.7 and works.