Не загружается fxml файл

Task7.fxml:

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.media.MediaView?>
<?import javafx.scene.text.Font?>

<VBox fx:id="vBoxParent" alignment="CENTER" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="first.java.HelloController">
   <children>
      <MediaView fx:id="nvVideo" />
      <Slider fx:id="sliderTIme" style="-fx-cursor: hand;">
         <padding>
            <Insets bottom="5.0" left="10.0" right="10.0" top="5.0" />
         </padding>
      </Slider>
      <HBox fx:id="hboxControls" alignment="CENTER_LEFT">
         <padding>
            <Insets bottom="10.0" />
         </padding>
         <children>
            <Button fx:id="buttonPPR" mnemonicParsing="false" style="-fx-cursor: hand;" />
            <HBox fx:id="hboxVolume">
               <HBox.margin>
                  <Insets left="5.0" />
               </HBox.margin>
               <children>
                  <Label fx:id="labelVolume" style="-fx-cursor: hand;" text="Label" />
                  <Slider fx:id="sliderVolume" max="1.0" style="-fx-cursor: hand;" />
               </children>
               <padding>
                  <Insets left="10.0" right="10.0" />
               </padding>
            </HBox>
            <Label fx:id="labelCurrentTime">
               <font>
                  <Font name="System Bold Italic" size="18.0" />
               </font>
               <HBox.margin>
                  <Insets left="10.0" />
               </HBox.margin>
            </Label>
            <Label fx:id="labelTotalTime">
               <font>
                  <Font name="System Bold Italic" size="18.0" />
               </font>
               <padding>
                  <Insets right="10.0" />
               </padding>
            </Label>
            <HBox alignment="CENTER_RIGHT" HBox.hgrow="ALWAYS">
               <children>
                  <Label fx:id="labelSpeed">
                     <font>
                        <Font name="System Bold" size="18.0" />
                     </font>
                     <HBox.margin>
                        <Insets right="10.0" />
                     </HBox.margin>
                  </Label>
                  <Label fx:id="labelFullScreen" style="-fx-cursor: hand;">
                     <padding>
                        <Insets right="10.0" />
                     </padding>
                  </Label>
               </children>
            </HBox>
         </children>
      </HBox>
   </children>
</VBox>

Task7.java:

package first.java;

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

public class Task7 extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("Task7.fxml"));
        primaryStage.setTitle("MediaPlayer");
        primaryStage.setScene(new Scene(root, 900, 500));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

HelloController.java:

package first.java;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
import javafx.util.Duration;

import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.concurrent.Callable;


public class HelloController implements Initializable {
    @FXML
    private VBox vboxParent;

    @FXML
    private MediaView mvVideo;
    private MediaPlayer mpVideo;
    private Media mediaVideo;

    @FXML
    private HBox hboxControls;

    @FXML
    private HBox hboxVolume;

    @FXML
    private Button buttonPPR;

    @FXML
    private Label labelCurrentTime;
    @FXML
    private Label labelTotalTime;
    @FXML
    private Label labelFullScreen;
    @FXML
    private Label labelSpeed;
    @FXML
    private Label labelVolume;

    @FXML
    private Slider sliderVolume;
    @FXML
    private Slider sliderTime;


    private boolean atEndOfVideo=false;
    private boolean isPlaying=true;
    private boolean isMuted=true;

    private ImageView ivPlay;
    private ImageView ivPause;
    private ImageView ivRestart;
    private ImageView ivVolume;
    private ImageView ivFullScreen;
    private ImageView ivMute;
    private ImageView ivExit;


    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        final int IV_SIZE = 25;
    mediaVideo=new Media(new File("src/resources/media/final.mp4").toURI().toString());
    mpVideo=new MediaPlayer(mediaVideo);
    mvVideo.setMediaPlayer(mpVideo);

    Image imagePlay=new Image(new File("src/resources/media/play-btn.png").toURI().toString());
    ivPlay=new ImageView(imagePlay);
    ivPlay.setFitHeight(IV_SIZE);
    ivPlay.setFitWidth(IV_SIZE);

    Image imageStop=new Image(new File("src/resources/media/stop-btn.png").toURI().toString());
    ivPause=new ImageView(imageStop);
    ivPause.setFitHeight(IV_SIZE);
    ivPause.setFitWidth(IV_SIZE);

    Image imageRestart=new Image(new File("src/resources/media/restart-btn.png").toURI().toString());
    ivRestart=new ImageView(imageRestart);
    ivRestart.setFitHeight(IV_SIZE);
    ivRestart.setFitWidth(IV_SIZE);

    Image imageVol=new Image(new File("src/resources/media/volume.png").toURI().toString());
    ivVolume=new ImageView(imageVol);
    ivVolume.setFitHeight(IV_SIZE);
    ivVolume.setFitWidth(IV_SIZE);

    Image imageFull=new Image(new File("src/resources/media/fullscreen.png").toURI().toString());
    ivFullScreen=new ImageView(imageFull);
    ivFullScreen.setFitHeight(IV_SIZE);
    ivFullScreen.setFitWidth(IV_SIZE);

    Image imageMute=new Image(new File("src/resources/media/mute.png").toURI().toString());
    ivMute=new ImageView(imageMute);
    ivMute.setFitHeight(IV_SIZE);
    ivMute.setFitWidth(IV_SIZE);

    Image imageExit=new Image(new File("src/resources/media/exitscreen.png").toURI().toString());
    ivExit=new ImageView(imageExit);
    ivExit.setFitHeight(IV_SIZE);
    ivExit.setFitWidth(IV_SIZE);

    buttonPPR.setGraphic(ivPause);
    labelVolume.setGraphic(ivMute);
    labelSpeed.setText("1X");
    labelFullScreen.setGraphic(ivFullScreen);

    buttonPPR.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent actionEvent) {
            Button buttonPlay=(Button) actionEvent.getSource();
            if(atEndOfVideo){
                sliderTime.setValue(0);
                atEndOfVideo=false;
                isPlaying=false;
            }
            if(isPlaying){
                buttonPlay.setGraphic(ivPlay);
                mpVideo.pause();
                isPlaying=false;
            }
            else{
                buttonPlay.setGraphic(ivPause);
                mpVideo.play();
                isPlaying=true;
            }
        }
    });

    hboxVolume.getChildren().remove(sliderVolume);

    mpVideo.volumeProperty().bindBidirectional(sliderVolume.valueProperty());

    bindCurrentTimeLabel();

    sliderVolume.valueProperty().addListener(new InvalidationListener() {
        @Override
        public void invalidated(Observable observable) {
            mpVideo.setVolume(sliderVolume.getValue());
            if(mpVideo.getVolume()!=0.0){
                labelVolume.setGraphic(ivVolume);
                isMuted=false;
            }
            else{
                labelVolume.setGraphic(ivMute);
                isMuted=true;
            }
        }
    });

    labelSpeed.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            if(labelSpeed.getText().equals("1X")){
                labelSpeed.setText("2X");
                mpVideo.setRate(2.0);
            }
            else{
                labelSpeed.setText("1X");
                mpVideo.setRate(1.0);
            }
        }
    });
    labelVolume.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            if(isMuted) {
                labelVolume.setGraphic(ivVolume);
                sliderVolume.setValue(0.2);
                isMuted=false;
            }
            else{
                labelVolume.setGraphic(ivMute);
                sliderVolume.setValue(0);
                isMuted=true;
            }
        }
    });

    labelVolume.setOnMouseEntered(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            if(hboxVolume.lookup("#sliderVolume")==null){
                hboxVolume.getChildren().add(sliderVolume);
                sliderVolume.setValue(mpVideo.getVolume());
            }
        }
    });

    hboxVolume.setOnMouseExited(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            hboxVolume.getChildren().remove(sliderVolume);
        }
    });

    vboxParent.sceneProperty().addListener(new ChangeListener<Scene>() {
        @Override
        public void changed(ObservableValue<? extends Scene> observableValue, Scene oldScene, Scene newScene) {
            if(oldScene==null && newScene!=null){
                mvVideo.fitHeightProperty().bind(newScene.heightProperty().subtract(hboxControls.heightProperty().add(20)));
            }
        }
    });

    labelFullScreen.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            Label label=(Label) mouseEvent.getSource();
            Stage stage=(Stage) label.getScene().getWindow();
            if(stage.isFullScreen()){
                stage.setFullScreen(false);
                labelFullScreen.setGraphic(ivFullScreen);
            }
            else{
                stage.setFullScreen(true);
                labelFullScreen.setGraphic(ivExit);
            }
            stage.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
                @Override
                public void handle(KeyEvent keyEvent) {
                    if(keyEvent.getCode()== KeyCode.ESCAPE){
                        labelFullScreen.setGraphic(ivFullScreen);
                    }
                }
            });
        }
    });

    mpVideo.totalDurationProperty().addListener(new ChangeListener<Duration>() {
        @Override
        public void changed(ObservableValue<? extends Duration> observableValue, Duration oldDuration, Duration newDuration) {
        sliderTime.setMax(newDuration.toSeconds());
        labelTotalTime.setText(getTime(newDuration));
        }
    });


    sliderTime.valueChangingProperty().addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(ObservableValue<? extends Boolean> observableValue, Boolean wasChanging, Boolean isChanging) {
            if(!isChanging){
                mpVideo.seek(Duration.seconds(sliderTime.getValue()));
            }
        }
    });

    sliderTime.valueProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
            double currentTime=mpVideo.getCurrentTime().toSeconds();
            if(Math.abs(currentTime-newValue.doubleValue())>0.5){
                mpVideo.seek(Duration.seconds(newValue.doubleValue()));
            }
            labelMatchEndVideo(labelCurrentTime.getText(),labelTotalTime.getText());
        }
    });

    mpVideo.currentTimeProperty().addListener(new ChangeListener<Duration>() {
        @Override
        public void changed(ObservableValue<? extends Duration> observableValue, Duration oldTime, Duration newTime) {
            if(!sliderTime.isValueChanging()){
                sliderTime.setValue(newTime.toSeconds());
            }
            labelMatchEndVideo(labelCurrentTime.getText(),labelTotalTime.getText());
        }
    });

    mpVideo.setOnEndOfMedia(new Runnable() {
        @Override
        public void run() {
            buttonPPR.setGraphic(ivRestart);
            atEndOfVideo=true;
            if(!labelCurrentTime.textProperty().equals(labelTotalTime.textProperty())){
                labelCurrentTime.textProperty().unbind();
                labelCurrentTime.setText(getTime(mpVideo.getTotalDuration())+" / ");
            }
        }
    });
    }

    public void bindCurrentTimeLabel(){
        labelCurrentTime.textProperty().bind(Bindings.createStringBinding(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return getTime(mpVideo.getCurrentTime())+" / ";
            }
        },mpVideo.currentTimeProperty()));
    }

    public String getTime(Duration time){

        int hours=(int) time.toHours();
        int minutes=(int) time.toMinutes();
        int seconds=(int) time.toSeconds();

        if(seconds>59) seconds=seconds%60;
        if(minutes>59) minutes=minutes%60;
        if(hours>59) hours=hours%60;

        if(hours>0) return String.format("%d:02d:%02d",
                hours,
                minutes,
                seconds);
        else return String.format("%02d:%02d",
                minutes,seconds);
    }

    public void labelMatchEndVideo(String labelTime, String labelTotalTime){
        for(int i=0;i<labelTotalTime.length();i++){
            if(labelTime.charAt(i)!=labelTotalTime.charAt(i)){
                atEndOfVideo=false;
                if(isPlaying) buttonPPR.setGraphic(ivPause);
                else buttonPPR.setGraphic(ivPlay);
                break;
            }
           else{
               atEndOfVideo=true;
               buttonPPR.setGraphic(ivRestart);
            }
        }
    }

}

В файле Task7.java вылазит ошибка во время выполнения программы:

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:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at [email protected]/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
    at [email protected]/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at [email protected]/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
    at [email protected]/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NullPointerException: Location is required.
    at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3324)
    at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3287)
    at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3255)
    at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3227)
    at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3203)
    at [email protected]/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3196)
    at first.java/first.java.Task7.start(Task7.java:13)
    at [email protected]/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
    at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
    at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at [email protected]/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    at [email protected]/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at [email protected]/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at [email protected]/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    ... 1 more
Exception running application first.java.Task7

Из-за чего она возникла?Почему у меня не работает load? Структура проекта


Ответы (0 шт):