skip to Main Content

I’m creating a JavaFx project in Visual Studio Code. And I was wanting to release a sound, but I ended up having the following problem:

The type javafx.scene.media.Media is not accessibleJava(16778666)

The type javafx.scene.media.MediaPlayer is not accessibleJava(16778666)

I’ve already added your modules and also seen them on the internet to add to pom.xml:

  modules:

    "vmArgs": "--module-path "C:/Program Files/Java/javafx-sdk-19/lib" --add-modules javafx.controls,javafx.fxml, javafx.media",

  Pom.xml:

        <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-media</artifactId>
        <version>13</version>
    </dependency>

I didn’t find anyone commenting on this specific error, if you can help me I would be very grateful

Note: The paths are correct as the other packages are working normally

The code:

    package com.example;

import java.io.File;
import java.io.IOException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;

/**
 * JavaFX App
 */
public class App extends Application {

    private static Scene scene;

    public static void main(String[] args) {
        launch();
    }

    @Override
    public void start(Stage stage) throws IOException {
        scene = new Scene(loadFXML("urna"));
        stage.setScene(scene);
        stage.setTitle("Urna EletrĂ´nica");
        stage.show();
    }

    public void songMedia(String path) {
        Media media = new Media(new File(path).toURI().toString());

        MediaPlayer mediaPlayer = new MediaPlayer(media);

        mediaPlayer.play();
    }

2

Answers


  1. you will need to add it manually to your dependencies first
    all info available on the JavaFX maven plugin github page
    https://github.com/openjfx/javafx-maven-plugin

    Login or Signup to reply.
  2. Looking at the way you have placed your path to the JavaFX library, Visual studio is reading the Javafx library incorrectly.
    On top of the Visual Studio menu,

    • Click on Run
    • Then select Open Configurations
    • Inside the curly braces under "configurations" add a comma then press Enter
    • Then add the lines below:

    "vmArgs": "--module-path=PATH_TO_JAVAFX_LIB --add-modules=MODULE_1,MODULES_2"

    Note: An example of the above arguments with the correct path format is as below;

    "vmArgs": "--module-path=lib/javafx-sdk-13/lib --add-modules=javafx.media,javafx.controls"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search