1

I'm having trouble with getting a JavaFX media player to work. I am getting an error message saying java.lang.reflect.InvocationTargetException. I researched this error message and found a post that said that I am calling 2 different classes with the same name. However I can't find what classes they are.

Does anyone have any experience with this? I think the message is only used with the JavaFx API. Here is the code:

import java.io.File;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.DoubleProperty;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Broadcaster extends Application 
{

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



@Override
  public void start(Stage primaryStage) {
    String workingDir = System.getProperty("C:/Users/Tito/Desktop");
    final File f = new File(workingDir, "Jeremy.wmv");

    final Media m = new Media(f.toURI().toString());
    final MediaPlayer mp = new MediaPlayer(m);
    final MediaView mv = new MediaView(mp);

    final DoubleProperty width = mv.fitWidthProperty();
    final DoubleProperty height = mv.fitHeightProperty();

    width.bind(Bindings.selectDouble(mv.sceneProperty(), "width"));
    height.bind(Bindings.selectDouble(mv.sceneProperty(), "height")); 



    mv.setPreserveRatio(true);

    StackPane root = new StackPane();
    root.getChildren().add(mv);

    final Scene scene = new Scene(root, 960, 540);
    scene.setFill(Color.BLACK);

    primaryStage.setScene(scene);
    primaryStage.setTitle("Full Screen Video Player");
    primaryStage.setFullScreen(true);
    primaryStage.show();

    mp.play();
  }
}

// This code was found on 
http://www.java2s.com/Code/Java/JavaFX/FullScreenVideoPlayer.htm
DAIRAV
  • 723
  • 1
  • 9
  • 31
Tito
  • 102
  • 9
  • 1
    This exception is not specific to JavaFx API. It means that by reflexion you are invoking a method or a constructor on an object which doesn't support it. – Guillaume Barré Dec 11 '18 at 09:15
  • 4
    Please [edit] your question to provide the full [stack trace](https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors). An `InvocationTargetException` is very rarely, if ever, the fundamental _cause_ of the error; you need to look at the `Caused by:`s in the stack trace. – Slaw Dec 11 '18 at 09:23
  • Thanks to Slaw and Nirekin. You guys helped with the problem. – Tito Dec 11 '18 at 10:02
  • 1
    If you think your solution will be helpful to others please feel free to answer your own question and accept the answer. Don't forget to [edit] your question as well to include the full stack trace; that way the question is complete and on-topic. Otherwise, feel free to delete this question. – Slaw Dec 11 '18 at 10:09

1 Answers1

0

The problem was my file location. For some reason the code isn't looking for the file in String workingDir = System.getProperty("C:/Users/Tito/Desktop"); It's looking for it in C:\Users\Tito\eclipse-workspace\Broadcast. I have to find out why. When I moved the media file to C:\Users\Tito\eclipse-workspace\Broadcast, it played the audio, but not the video.

Tito
  • 102
  • 9
  • I was able to find this by printing the printeStackTrace in a try catch. – Tito Dec 11 '18 at 10:20
  • 3
    By the way, `System.getProperty("C:/Users/Tito/Desktop")` means you're looking for the value mapped to the _key_ (which is `"C:/Users/Tito/Desktop"`). The value will likely be `null` here. Based on the variable name(`workingDir`) is seems like it should be `System.getProperty("user.dir")` which will return the working directory. – Slaw Dec 11 '18 at 10:29