0

I'm struggling with a javafx + weld problem.

I'm building application that should switch scenes/views. Application is using weld CDI.

I was trying several approaches and none of them is working. Currently my application is based on a solution from this link https://dzone.com/articles/fxml-javafx-powered-cdi-jboss.

This method (copied from mentioned solution) works just fine.

public void launchJavaFXApplication(@Observes @StartupScene Stage s) {
    mainStage = s;

    InputStream is = null;

    try {
        is = getClass().getResourceAsStream("Views/LoginView.fxml");
        Parent root = (Parent) fxmlLoader.load(is);
        s.setTitle("Login");
        s.setScene(new Scene(root, 900, 600));
        s.show();
    } catch (IOException e) {
        throw new IllegalStateException("cannot load FXML login screen", e);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            }
        }
    }
}

It loads first screen, but then I'm trying to switch view to another fxml file that is located side by side with mentioned LoginView, the getClass().getResourceAsStream("Views/LoginView.fxml") returns null. The second view (MainView) is being fired by using button on the login view. I was trying to load MainView instead of LoginView in the launchJavaFXApplication method and it works just fine.

The second problem: when trying to place fxml control (even a very simple one without controller) inside the fxml file loaded with launchJavaFXApplication method, InputStream is also null.

If something is missing please ask and I can put some more code samples if it may clarify the situation.

regards, Bartek

Bartek
  • 149
  • 3
  • 13
  • Which package is the class containing the code you posted in, and which package is the class where you calling `getClass().getResourceAsStream("Views/LoginView.fxml") ` and getting null in? – James_D Mar 14 '17 at 18:45
  • I solved the first problem by creating another instance of fxmlLoader. Still there is a second problem - trying to include one fxml inside the other causes fxmlLoader.load() return null. Both Fxmls are in the same direcotry (Views). Loading MainView without fx:include works. When I add fxmlLoader returns null. – Bartek Mar 15 '17 at 15:24

0 Answers0