#"Might be null" problem withFXMLLoader.load.getClass().getResource()

9 messages · Page 1 of 1 (latest)

sonic copper
#

I am trying to run this small code but I have a problem at this line of the code that I don't know how to fix.

vernal pecanBOT
#

This post has been reserved for your question.

Hey @sonic copper! 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.

quartz ruin
#

I know nothing about JavaFX, but this suggests that you have a module-info.java
Generally speaking, a screenshot may have been useful if it showed your project layout, but:

  • it doesn't show your project layout, so the screenshot is 100% useless
  • can't copy/paste the code and verify it's all there
  • can't copy/paste the error and it's truncated
sonic copper
#

This is the project layout

#
package InterfacePackage;

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


public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("InterfacePackage/HyttInterface2.fxml"));
        Parent root = loader.load();
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root, 800, 500));
        primaryStage.show();
    }

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

#
package InterfacePackage;

public class Controller {
    public void loginButtonClicked() {
        System.out.println("User logged in... ");
    }
}
#

Caused by: java.lang.IllegalAccessException: class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot access class InterfacePackage.Main (in module com.example.summerholiday) because module com.example.summerholiday does not export InterfacePackage to module javafx.graphics

twin island
#

You have to follow the error message and do what it tells you to do:

export module com.example.summerholiday to javafx.graphics