Title: Problem With JavaFX/Intellij Setting When Try To Use LauncherImpl For Preloader
Tags: java;intellij-idea;javafx;preloader
Question: potterbreanna@example.com/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 @potterbreanna@example.com(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!

Here is the accepted answer: You have at least two options:
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.
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.
Comment for this answer: 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?
Comment for this answer: 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!!!!
Comment for this answer: 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.
Comment for this answer: @ndbd [`Application#notifyPreloader(Preloader.PreloaderNotification)`](https://openjfx.io/javadoc/14/javafx.graphics/javafx/application/Application.html#notifyPreloader(javafx.application.Preloader.PreloaderNotification)).


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:01/09/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<java><intellij-idea><javafx><preloader>', 'Title': 'Problem With JavaFX/Intellij Setting When Try To Use LauncherImpl For Preloader', 'ViewCount': 454, 'id': 59656908, 'user_AboutMe': None, 'user_AccountId': 17203327.0, 'user_DisplayName': 'Alex Yuan', 'user_Reputation': 35.0, 'user_Views': 6.0, 'user_id': 12454460.0}}