0

(Sorry, by mistake I've deleted the old version of this post. Despite of following the advices, the problem is still there.)

(If my question isn't good or acceptable, I would appreciate to know why! Thanks!)

Hi! I'm using IntelliJ with Gradle, and I am following some udemy-tutorial. Please, could you help me with that problem? I've been googling on that for hours. Thanks a lot! (Please don't be to severe with me. I'm a beginner both in java and on StackOverFlow (and in the English language) :)

All the best, M.I.

My code:

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Media;
import javafx.scene.media.MediaPlayer;

import java.net.URL;

public class SnakeGame extends Application {

    private MediaPlayer mediaPlayer;

    @Override
    public void start(Stage primaryStage) throws Exception {
        String musicFile = "snakeMusic.mp3";
        URL fileUrl = getClass().getResource(musicFile);
        System.out.println(fileUrl);
        Media media = new Media(fileUrl.toString());
        mediaPlayer = new MediaPlayer(media);

    }

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

My error:

/Users/magisterinformaticus/MySnake/src/main/java/SnakeGame.java:44: error: cannot find symbol
import javafx.scene.Media;
                   ^
  symbol:   class Media
  location: package javafx.scene 

My build.gradle:

plugins {
    id 'java'
    // add
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

// add
mainClassName = 'SnakeGame'

group 'org.example'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

javafx {
    version = "11"
    modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.media']
}

0 Answers0