Home > Java > javaTutorial > How to Fix JavaFX Media Application Module Errors in Java 9 ?

How to Fix JavaFX Media Application Module Errors in Java 9 ?

Linda Hamilton
Release: 2024-12-12 14:00:16
Original
828 people have browsed it

How to Fix JavaFX Media Application Module Errors in Java 9 ?

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
Copy after login

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:

  • Adding javafx.media to --add-modules: Specify --add-modules javafx.controls,javafx.graphics,javafx.media when launching the application.
  • Making your code modular: Create a module descriptor (module-info.java) and specify requires javafx.controls; and requires javafx.media;.
  • Using a JDK that includes JavaFX: Certain JDK distributions, such as BellSoft Liberica or Azul Zulu, include OpenJFX modules.

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template