当我拥有JDK 8(我认为吗?)和e(fx)clipse附带的默认JavaFX时,我做了一个项目。它运行良好,但是最近我将它们升级到JDK 13.0.1和JFX 13,现在由于它找不到Media类而崩溃了。
该项目很简单,它只是从mp4文件的中间播放,并在1秒钟后暂停视频。这是代码:
package test;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
import javafx.util.Duration;
public class main extends Application {
public static void main(String[] args) {
launch(args);
}
public MediaPlayer mp;
public Timeline tl;
@Override
public void start(Stage win) throws Exception {
Media m=new Media(ClassLoader.getSystemResource("test/videoplayback.mp4").toExternalForm());
mp=new MediaPlayer(m);
mp.setVolume(0.5);
MediaView mv=new MediaView(mp);
AnchorPane pane=new AnchorPane();
pane.getChildren().addAll(mv);
Scene s=new Scene(pane,640,360);
win.setScene(s);
win.show();
p();
}
public void p() {
mp.play();
tl=new Timeline(
new KeyFrame(Duration.seconds(0.01),event->{
mp.seek(mp.getStartTime().add(Duration.seconds(118.4)));
}),
new KeyFrame(Duration.seconds(1),event->mp.pause())
);
tl.playFromStart();
}
}
这是错误
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.lang.NoClassDefFoundError: javafx/scene/media/Media
at test.main.start(main.java:28)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Caused by: java.lang.ClassNotFoundException: javafx.scene.media.Media
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 10 more
Exception running application test.main
我已将整个javafx库添加到构建路径,包括javafx.media.jar。其他常见的javaFX类似乎也可以工作,但是javafx.scene.media下没有任何工作。我做了一个新项目,就和这个项目一样。一切正常,除了javafx.scene.media下的类。
我的脑细胞不足,无法知道该从哪里去,所以请帮助我。预先感谢!