0

I have a issue, not being able to import MediaPlayer in my JavaFX project. I am using IntelliJ with a Maven build, JDK 19. I also looked here for answers but they didn't work for me: JavaFX MediaPlayer import

I have tried to fix by writing in module-info.java requires javafx.media; and by adding javafx-media dependency, but it didn't work.

The only error is: java: cannot find symbol

Thanks in advance for any answer/suggestion

`<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>MediaPlayer</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>MediaPlayer</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <junit.version>5.9.1</junit.version>      </properties>

  <dependencies>
    <dependency>
      <groupId>org.openjfx</groupId>
      <artifactId>javafx-controls</artifactId>
      <version>19</version>
    </dependency>
    <dependency>
      <groupId>org.openjfx</groupId>
      <artifactId>javafx-fxml</artifactId>
      <version>19</version>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.openjfx</groupId>
      <artifactId>javafx-media</artifactId>
      <version>19</version>
    </dependency>
  </dependencies>

  <build>
        <plugins>
            <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.10.1</version>
        <configuration>
          <source>19</source>
          <target>19</target>
        </configuration>
            </plugin>
      <plugin>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-maven-plugin</artifactId>
        <version>0.0.8</version>
        <executions>
          <execution>
Default configuration for running with: mvn clean javafx:run -->
            <id>default-cli</id>
            <configuration>
              <mainClass>com.example.mediaplayer/com.example.mediaplayer.HelloApplication</mainClass>
              <launcher>app</launcher>
              <jlinkZipName>app</jlinkZipName>
              <jlinkImageName>app</jlinkImageName>
              <noManPages>true</noManPages>
              <stripDebug>true</stripDebug>
              <noHeaderFiles>true</noHeaderFiles>
            </configuration>
          </execution>
        </executions>
      </plugin>
          </plugins>
  </build>
</project>`
erki
  • 1
  • 1
  • 1
    Does `requires javafx.media;` give an error? You may need to rebuild the maven project (which downloads dependencies and updates class/module paths, etc.), depending on your IDE. – James_D May 15 '23 at 16:33
  • 3
    The approach in the answer to the question you linked worked for me. What does "doesn't work" mean? You note a "syntax-error" in tags. What is the syntax error? A syntax error will create a compile error. Provide the output of the compilation error in the question, the compile command used, and the code that doesn't compile so your issue can be replicated (e.g. [mcve]). If it isn't actually a syntax error, but is a runtime error, then do the same, but provide the stack trace for the runtime error and the execution command to run the app. – jewelsea May 15 '23 at 18:31

1 Answers1

0

The answer is very simple: If the Intellij gives the error that it cannot find the symbol, just need to update Intellij from JetBrains ToolBox.

erki
  • 1
  • 1