Я создаю диалоговое окно, но dialog.showAndWait вызывает ошибки
"Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException"
эта ошибка появляется.
Главный класс:
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Favori Filmlerim");
primaryStage.setScene(new Scene(root, 900, 600));
primaryStage.show();
}
Класс контроллера:
package sample;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.layout.BorderPane;
import java.io.IOException;
import java.util.Optional;
public class Controller {
@FXML
private BorderPane anaPencere;
@FXML
void filmEkleDialog(ActionEvent event) throws IOException {
Dialog<ButtonType> dialog = new Dialog<>();
dialog.initOwner(anaPencere.getScene().getWindow());
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(getClass().getResource("yeniFilmDialog.fxml"));
dialog.setTitle("Yeni Film Ekle");
dialog.getDialogPane().setContent(fxmlLoader.load());
dialog.getDialogPane().getButtonTypes().add(ButtonType.APPLY);
dialog.getDialogPane().getButtonTypes().add(ButtonType.CANCEL);
Optional<ButtonType> sonuc = dialog.showAndWait();
if (sonuc.get() == ButtonType.APPLY){
YeniFilmDialog dialogController = fxmlLoader.getController();
dialogController.yeniNotuEkle();
}
}
@FXML
void uygulamayiKapat(ActionEvent event) {
Platform.exit();
}
}