#"Might be null" problem withFXMLLoader.load.getClass().getResource()
9 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @sonic copper! Please use
/closeor theClose Postbutton 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.
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
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
You have to follow the error message and do what it tells you to do:
export module com.example.summerholiday to javafx.graphics