Afterburner.fx fxml load error

dependency-injection, fxml, fxmlloader, javafx

Solution

Caused by: java.lang.IllegalStateException: Location is not set. 

Probably you do not have *.fxml files in JAR. I had the same problem. Try to add resources filtering to your POM file, like here: https://github.com/AdamBien/afterburner.fx/blob/master/pom.xml

    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.fxml</include>
                <include>**/*.css</include>
                <include>**/*.properties</include>
            </includes>
        </resource>
        <resource>
            <directory>src/test/java</directory>
            <includes>
                <include>**/*.fxml</include>
                <include>**/*.css</include>
                <include>**/*.properties</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.xml</include>
                <include>**/*.css</include>
                <include>**/*.css</include>
                <include>**/*.properties</include>
            </includes>
        </resource>
    </resources>

This allow to copy .fxml files to packages in JAR file.

Problem

I try to use Afterburner.fx for DI in my project. I take followme.fx example and I try to apply to my project. But I don't know what's wrong because I follow example but when I run app, I get these exception: ``` java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) Caused by: 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$151(LauncherImpl.java:182) at com.sun.javafx.application.LauncherImpl$$Lambda$50/1030870354.run(Unknown Source) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalStateException: Location is not set. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2438) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2413) at com.airhacks.afterburner.views.FXMLView.loadSynchronously(FXMLView.java:87) at com.airhacks.afterburner.views.FXMLView.initializeFXMLLoader(FXMLView.java:96) at com.airhacks.afterburner.views.FXMLView.getView(FXMLView.java:108) at com.******.controladores.MainApp.start(MainApp.java:44) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$158(LauncherImpl.java:863) at com.sun.javafx.application.LauncherImpl$$Lambda$53/1821793753.run(Unknown Source) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$171(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl$$Lambda$46/1637506559.run(Unknown Source) at com.sun.javafx.application.PlatformImpl.lambda$null$169(PlatformImpl.java:295) at com.sun.javafx.application.PlatformImpl$$Lambda$48/313834886.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$170(PlatformImpl.java:294) at com.sun.javafx.application.PlatformImpl$$Lambda$47/2117255219.run(Unknown Source) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$144(WinApplication.java:101) at com.sun.glass.ui.win.WinApplication$$Lambda$36/764308918.run(Unknown Source) ... 1 more Exception running application com.******.controladores.MainApp ``` Directory structure: Main class ``` package com.******.controladores; import com.airhacks.afterburner.injection.Injector; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Logger; import static java.util.logging.Logger.getLogger; import javafx.application.Application; import static javafx.application.Application.launch; import javafx.scene.Scene; import javafx.stage.Stage; public class MainApp extends Application { private static final Logger LOG = getLogger(MainApp.class.getName()); @Override public void start(Stage stage) { Map<Object, Object> customProperties = new HashMap<>(); Injector.setConfigurationSource(customProperties::get); LoginView loginView = new LoginView(); Scene scene = new Scene(loginView.getView()); stage.setScene(scene); stage.show(); } @Override public void stop() throws Exception { Injector.forgetAll(); } public static void main(String[] args) { launch(args); } } ``` LoginView class ``` package com.******.controladores; import com.airhacks.afterburner.views.FXMLView; public class LoginView extends FXMLView { } ``` LoginPresenter class ``` package com.****.controladores; import com.****.dao.usuarioDAO; import com.****.modelos.usuario; import java.net.URL; import java.util.List; import java.util.ResourceBundle; import java.util.logging.Logger; import static java.util.logging.Logger.getLogger; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ChoiceBox; import javafx.scene.control.PasswordField; import javafx.scene.image.Image; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; import javafx.stage.Stage; import javafx.stage.WindowEvent; import javax.inject.Inject; public class LoginPresenter implements Initializable { private static final Logger LOG = getLogger(LoginPresenter.class.getName()); @FXML Button btnAceptar; @FXML ChoiceBox lstUsuario; @FXML PasswordField txtClave; @Inject private DataModel datos; @Override public void initialize(URL url, ResourceBundle rb) { List<Usuario> usuarios = new UsuarioDAO().obtenListausuariosPorEstado(true); lstUsuario.getItems().addAll(usuarios); btnAceptar.setOnAction((ActionEvent event) -> { validarCampos(); }); txtClave.setOnKeyPressed((KeyEvent ke) -> { if (ke.getCode().equals(KeyCode.ENTER)) { validarCampos(); } }); } } ``` Login.fxml ``` <?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?> <?import javafx.scene.control.*?> <?import javafx.scene.image.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.text.*?> <VBox alignment="CENTER" prefHeight="338.0" prefWidth="286.0" styleClass="fondo" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.****.controladores.LoginPresenter"> <children> <Label alignment="CENTER" contentDisplay="CENTER" nodeOrientation="LEFT_TO_RIGHT" styleClass="titulo" text="Inicio de sesión"> <font> <Font name="Segoe UI" size="30.0" /> </font> </Label> <Pane prefHeight="59.0" prefWidth="286.0" /> <VBox alignment="CENTER"> <children> <Label text="Usuario"> <font> <Font name="System Bold" size="12.0" /> </font> </Label> <ChoiceBox fx:id="lstUsuario" prefWidth="150.0" /> <Label text="Clave"> <font> <Font name="System Bold" size="12.0" /> </font> </Label> <PasswordField fx:id="txtClave" promptText="Introduce tu clave" /> </children> </VBox> <Pane prefHeight="59.0" prefWidth="286.0" /> <Button fx:id="btnAceptar" contentDisplay="CENTER" mnemonicParsing="false" text="Aceptar" textAlignment="CENTER"> </Button> <Pane prefHeight="59.0" prefWidth="286.0" /> </children> </VBox> ``` POM ``` <dependency> <groupId>com.airhacks</groupId> <artifactId>afterburner.fx</artifactId> <version>1.6.0</version> </dependency> ```

Original source