I am new to JavaFX and Im currently working with an application that plays a video(.MP4) at the beginning of the application, however, I cant seem to make it work! Please tell me what's wrong with my code:
import java.io.File;
import javafx.geometry.Pos;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.text.Text;
public class NoConnection {
private StackPane root;
public NoConnection(){
Media media = null;
try{
File video = new File("video.mp4");
String url = video.toURI().toURL().toString();
System.out.println("URL: "+url);
media = new Media(url);
}catch(Exception e){
System.err.println(e.toString());
}
MediaPlayer player = new MediaPlayer(media);
player.play();
MediaView mediaView = new MediaView(player);
root = new StackPane();
root.setAlignment(Pos.CENTER);
root.setStyle("-fx-background-color : white;");
root.getChildren().add(mediaView);
}
public StackPane getLayout(){
return root;
}
}
By the way, Im running Windows XP!
Here's the complete error:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/11461388.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/31501478.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$38/29531133.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)