eu estou começando a estudar javafx e queria fazer uma simples tela que reproduzisse um video o meu codigo é o seguinte:
private String VIDEO_URL = getClass().getResource("C:\\Users\\Victor\\Videos\\amostra.mp4").toString();
public static void main(String[] args) {
launch(); // 2
}
@Override
public void start(Stage palco) throws Exception {
Media media = new Media(VIDEO_URL); // 1
MediaPlayer mediaPlayer = new MediaPlayer(media); // 2
MediaView mediaView = new MediaView(mediaPlayer); // 3
StackPane raiz = new StackPane();
raiz.getChildren().add(mediaView); // 4
Scene cena = new Scene(raiz, 600, 400);
palco.setTitle("Tocando Video em JavaFX");
palco.setScene(cena);
palco.show();
mediaPlayer.play(); // 4
}
mas ele exibe o erro:
Exception in Application constructor
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: Unable to construct Application instance: class hellofx.HELLOFX
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:890)
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.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:802)
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.NullPointerException
at hellofx.HELLOFX.<init>(HELLOFX.java:24)
... 14 more
Exception running application hellofx.HELLOFX
C:\Users\Victor\Documents\NetBeansProjects\HELLOFX\nbproject\build-impl.xml:1339: The following error occurred while executing this line:
C:\Users\Victor\Documents\NetBeansProjects\HELLOFX\nbproject\build-impl.xml:948: Java returned: 1
a linha 24 seria a:
private String VIDEO_URL = getClass().getResource("C:\\Users\\Victor\\Videos\\amostra.mp4").toString();
o que pode ser?