package javafx.media does not exist


Question

I'm new to programming and don't know what to do... jGRASP gives this error (the title) when i try to run an mp3 file using java via this code :

import javafx.scene.media.MediaPlayer;
import javafx.scene.media.Media;

public class hehe{

  public static void main(String[]args){

    String krow="hoho.mp3";
    Media trial = new Media(krow);
    MediaPlayer Ply = new MediaPlayer(trial);
    Ply.play();

  }

}

I searched for a solution but couldn't find one.

1
2
11/27/2013 3:41:20 PM

Accepted Answer

You need to download e(fx)clipse plugin or use NetBeans or IntelliJ. If you are using 'regular' Eclipse, you need to add jfxrt.jar to your classpath.

What you are using is JavaFX. It comes along with your JDK. However, jfxrt.jar is not on standard classpath.

In spite of resolving that, your program won't run because running JavaFX program is different from running 'usual' Java programs. You need to extend the Application class and create a scene graph.

Have a look here on how to get started.

3
11/27/2013 3:43:14 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon