#Problems initialising a JavaFX + Spring Application

8 messages · Page 1 of 1 (latest)

patent lichen
#
package dev.converer.cunit;

import dev.converer.cunit.controllers.CunitController;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import net.rgielen.fxweaver.core.FxWeaver;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;

import java.io.IOException;
import java.util.Objects;

// Make JavaFX and Spring coexist
public class JavaFxApplication extends Application {

    private ConfigurableApplicationContext applicationContext;
    private FxWeaver fxWeaver;
    private Parent root;
    final private FXMLLoader loader = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("main-stage.fxml")));

    public JavaFxApplication() throws IOException {

    }

    @Override
    public void init() throws Exception {
        String[] args = getParameters().getRaw().toArray(new String[0]);

        this.applicationContext = new SpringApplicationBuilder()
                .sources(CunitApplication.class)
                .run(args);

        if (applicationContext.containsBean("fxWeaver"))
            fxWeaver = applicationContext.getBean(FxWeaver.class);
        else
            System.err.println("Cannot load FxWeaver.");
    }

    @Override
    public void start(Stage stage) throws IOException {
        if (fxWeaver != null)
            root = loader.load();
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }

    @Override
    public void stop() {
        this.applicationContext.close();
        Platform.exit();
    }

}```


I am trying to make a simple converter app as a course project in Java.

I am getting problems initialising the app. I will show the error below.
gentle smeltBOT
#

This post has been reserved for your question.

Hey @patent lichen! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

patent lichen
carmine python
#

getResource returns bull

#

null*

#

make sure that dev/converer/cunit/main-stage.fxml is present in your resource directory