【发布时间】:2015-03-16 06:54:25
【问题描述】:
我是 JavaFX 的新手,我目前正在使用一个在应用程序开头播放视频 (.MP4) 的应用程序,但是,我似乎无法让它工作!请告诉我我的代码有什么问题:
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;
}
}
顺便说一下,我运行的是 Windows XP!
这是完整的错误:
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)
【问题讨论】:
-
File存在吗?你试过video.toURI().toURL().toExternalForm()吗?您使用的是哪个 Java/JavaFX 版本? -
当然!!它存在!
-
这是操作系统问题吗,我目前使用的是 Windows XP。
-
请放慢速度,慢慢来,解释你的问题。你还没有表达出什么是行不通的。是的:从 Java 8 开始,Oracle 正式不再支持 WindowsXP。
-
它在 Windows 7 中运行!不在 XP 中!