2
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.IllegalAccessError: class MainFile.Main (in unnamed module @0x234bef66) cannot access class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.application to unnamed module @0x234bef66
    at MainFile.Main.main(Main.java:100)
    ... 11 more
Exception running application MainFile.Main

This is the exception that I am getting and I know for a fact that it is not with the problem of the code and this has something to do with IntelliJ but I don't know what should I do to fix this.

Some possible approaches that I found can perhaps work

1) VM Option in the Configuration 2) add-export

Please let me know how I might be able to solve this problem. Thanks in advance!

Alex Yuan
  • 35
  • 5

1 Answers1

1

You have at least two options:

  1. Add a VM argument to export the needed package to your code. Since your code is in the unnamed module, such an argument would look like:

    --add-exports javafx.graphics/com.sun.javafx.application=ALL-UNNAMED
    

    Note: Replace ALL-UNNAMED with your module's name if and when you make your code modular.

    Where you add this argument depends on how you're application is being launched. You have to ensure your application uses that argument when being compiled and executed, including after deployment.

  2. Set the javafx.preloader system property before launching the application and stop using LauncherImpl altogether. This can be done on the command line:

    -Djavafx.preloader=com.example.PreloaderImpl
    

    Or in the main method:

    public static void main(String[] args) {
      System.setProperty("javafx.preloader", PreloaderImpl.class.getName());
      Application.launch(ApplicationImpl.class, args);
    }
    

The second option is probably the easier to implement of the two.

Slaw
  • 37,820
  • 8
  • 53
  • 80
  • I saw one of your (now-deleted) comments, which mentioned that your main method was not the only place you wanted to use `LauncherImpl`. Not sure exactly what you're trying to do, but note that you can only launch one JavaFX application per JVM instance. – Slaw Jan 09 '20 at 12:14
  • Na I just figure it out XD thank you so much, I first tried the first option u give but then I realized the second one is way easier and I am having a properly working splash scene!! thank you!!!! – Alex Yuan Jan 09 '20 at 18:58
  • probably similar to the OP I sued LauncherImpl twice, namely once to load the application, and once as `LauncherImpl.notifyPreloader(this, new Preloader.ProgressNotification(progress));` to notify the preloader of progress. Using LauncherImpl of course crashes the application. How would I replace this second usage of LauncherImp? – ndbd Sep 18 '20 at 13:49
  • 1
    @ndbd [`Application#notifyPreloader(Preloader.PreloaderNotification)`](https://openjfx.io/javadoc/14/javafx.graphics/javafx/application/Application.html#notifyPreloader(javafx.application.Preloader.PreloaderNotification)). – Slaw Sep 18 '20 at 22:47