title: JavaFX MediaPlayer throws java.lang.reflect.InvocationTargetException
body: <p>I've been trying to experiment with the JavaFX MediaPlayer class, and found the following example code in a different thread: </p>
  
  <pre><code>import java.net.URI;
  import java.net.URISyntaxException;
  
  import javafx.application.Application;
  import javafx.scene.Group;
  import javafx.scene.Scene;
  import javafx.scene.media.Media;
  import javafx.scene.media.MediaPlayer;
  import javafx.scene.media.MediaView;
  import javafx.stage.Stage;
  
  public class test extends Application {
  
      @Override
      public void start(Stage primaryStage)
      {
          //Add a scene
          Group root = new Group();
          Scene scene = new Scene(root, 500, 200);
          URI file = null;
          try {
              file = new URI("/home/thomas/voodoo.mp3");
          } catch (URISyntaxException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              System.out.println("POOR URI SYNTAX");
          }
          Media pick = new Media(file.toString());
          MediaPlayer player = new MediaPlayer(pick);
          player.play();
  
          //Add a mediaView, to display the media. Its necessary !
          //This mediaView is added to a Pane
          MediaView mediaView = new MediaView(player);
          ((Group)scene.getRoot()).getChildren().add(mediaView);
  
          //show the stage
          primaryStage.setTitle("Media Player");
          primaryStage.setScene(scene);
          primaryStage.show();
      }
      public static void main(String[] args) {
           launch(args);
      }
  }
  </code></pre>
  
  <p>I adjusted the file path to point to a real audio file (/home/thomas/voodoo.mp3) and tried running it, but the console output is the following:</p>
  
  <pre><code>Exception in Application start method
  java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
      at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
  Caused by: java.lang.RuntimeException: Exception in Application start method
      at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.IllegalArgumentException: uri.getScheme() == null! uri == '/home/thomas/voodoo.mp3'
      at com.sun.media.jfxmedia.locator.Locator.&lt;init&gt;(Locator.java:211)
      at javafx.scene.media.Media.&lt;init&gt;(Media.java:393)
      at test.start(test.java:28)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
      at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
      at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
      at com.sun.glass.ui.gtk.GtkApplication.lambda$null$5(GtkApplication.java:139)
      ... 1 more
  Exception running application test
  </code></pre>
  
  <p>Is there something wrong with my setup, or with my code?</p>
  
  <p>Thanks for the help!</p>
  
  <p>EDIT:</p>
  
  <p>Changed to <code>Media pick = new Media(new File("/home/thomas/voodoo.mp3").toURI().toString());</code> as per Nash's suggestion, but it still doesn't work. The console output is a little different now, though. </p>
  
  <pre><code>Exception in Application start method
  java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
      at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
  Caused by: java.lang.RuntimeException: Exception in Application start method
      at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: MediaException: UNKNOWN : com.sun.media.jfxmedia.MediaException: Could not create player! : com.sun.media.jfxmedia.MediaException: Could not create player!
      at javafx.scene.media.MediaException.exceptionToMediaException(MediaException.java:146)
      at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:511)
      at javafx.scene.media.MediaPlayer.&lt;init&gt;(MediaPlayer.java:414)
      at test.start(test.java:20)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
      at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
      at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
      at com.sun.glass.ui.gtk.GtkApplication.lambda$null$5(GtkApplication.java:139)
      ... 1 more
  Caused by: com.sun.media.jfxmedia.MediaException: Could not create player!
      at com.sun.media.jfxmediaimpl.NativeMediaManager.getPlayer(NativeMediaManager.java:274)
      at com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:118)
      at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:467)
      ... 11 more
  Exception running application test
  </code></pre>