应用程序启动方法java.lang.reflect.InvocationTargetException场景生成器中出现异常

应用程序启动方法java.lang.reflect.InvocationTargetException场景生成器中出现异常,java,javafx,scenebuilder,Java,Javafx,Scenebuilder,我做错了什么?我在看这个视频() 我也写了同样的,只是它在Intellij上 我仍然猜测它与config或javafx/jdk版本有关 Main.java文件: package sample; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage;

我做错了什么?我在看这个视频() 我也写了同样的,只是它在Intellij上 我仍然猜测它与config或javafx/jdk版本有关

Main.java文件:

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}
package sample;
import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.FileChooser;
public class Controller {

    private MediaPlayer mediaPlayer;


    private String filePath;

    @FXML
    private MediaView mediaView;
    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private void handleButtonAction(ActionEvent event) {
        FileChooser fileChooser = new FileChooser();
        FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("Select a File", "*.mp4");
            fileChooser.getExtensionFilters().add(filter);
            File file = fileChooser.showOpenDialog(null);
            filePath = file.toURI().toString();

            if (filePath != null) {
                Media media = new Media(filePath);
                mediaPlayer = new MediaPlayer(media);
                mediaView.setMediaPlayer(mediaPlayer);
                mediaPlayer.play();
            }
    }

    @FXML
    void initialize() {

    }
}
Controller.java文件:

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}
package sample;
import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.FileChooser;
public class Controller {

    private MediaPlayer mediaPlayer;


    private String filePath;

    @FXML
    private MediaView mediaView;
    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private void handleButtonAction(ActionEvent event) {
        FileChooser fileChooser = new FileChooser();
        FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("Select a File", "*.mp4");
            fileChooser.getExtensionFilters().add(filter);
            File file = fileChooser.showOpenDialog(null);
            filePath = file.toURI().toString();

            if (filePath != null) {
                Media media = new Media(filePath);
                mediaPlayer = new MediaPlayer(media);
                mediaView.setMediaPlayer(mediaPlayer);
                mediaPlayer.play();
            }
    }

    @FXML
    void initialize() {

    }
}
sample.fxml文件:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.media.MediaView?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
   <center>
      <StackPane prefHeight="150.0" prefWidth="200.0" BorderPane.alignment="CENTER">
         <children>
            <MediaView fx:id="mediaView" fitHeight="200.0" fitWidth="200.0" />
         </children>
      </StackPane>
   </center>
   <bottom>
      <HBox alignment="CENTER" prefHeight="40.0" prefWidth="600.0" spacing="50.0" BorderPane.alignment="CENTER">
         <children>
            <Button mnemonicParsing="false" onAction="#handleButtonAction" text="Open" />
            <Button mnemonicParsing="false" text="Play" />
            <Button mnemonicParsing="false" text="pause" />
            <Button mnemonicParsing="false" text="Stop" />
         </children>
      </HBox>
   </bottom>
</BorderPane>

我做错了什么?我在看这个视频() 我也写了同样的,只是它在Intellij上


我仍然猜测它与config或javafx/jdk版本有关

您可以添加stacktrace吗?您是否将
jphonix
libarary添加到ide。。?您的XML文件正常吗?
InvocationTargetException
从来都不是基本错误,它本身不会告诉我们任何有用的信息。请将您的问题添加到整个。