Module error when running JavaFx media application
When attempting to run a JavaFX 11 application, the following error message appears:
Exception in thread "JavaFX Application Thread" java.lang.IllegalAccessError: class com.sun.media.jfxmediaimpl.NativeMediaManager (in unnamed module @0x4d7be377) cannot access class com.sun.glass.utils.NativeLibLoader (in module javafx.graphics) because module javafx.graphics does not export com.sun.glass.utils to unnamed module @0x4d7be377
This error stems from a change in Java's module system introduced in Java 9. JavaFX, which was previously part of the Java runtime environment, is now distributed as a set of modules.
To resolve this issue, ensure that the javafx.media module is resolved correctly. This can be achieved by:
If you choose to use the third approach, note that the main class should not extend Application and a separate launcher class must be created to initialize JavaFX.
Additionally, it is important to ensure that JavaFX dependencies are not placed on the classpath, as this can lead to module resolution issues. Instead, include them in the module path or use a modularized approach.
The above is the detailed content of How to Fix JavaFX Media Application Module Errors in Java 9 ?. For more information, please follow other related articles on the PHP Chinese website!