我有以下代码:package pl.javastart.youtufy.controller;import java.net.URL;import java.util.ResourceBundle;import javafx.application.Platform;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.fxml.FXML;import javafx.fxml.Initializable;import javafx.scene.Node;import javafx.scene.control.Button;import javafx.scene.control.Label;import javafx.scene.control.ToggleButton;import javafx.scene.web.WebEngine;import javafx.stage.Stage;public class ConnectionErrorController implements Initializable { @FXML private Label infoLabel; @FXML private Button tryButton; @FXML private Button exitButton; @Override public void initialize(URL location, ResourceBundle resources) { MainController mc = new MainController(); infoLabel.setText("Connection lost, please try again"); tryButton.setText("try again"); exitButton.setText("exit"); tryButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { WebEngine webEngine = mc.getContentPaneController().getVideoWebView().getEngine(); // 1 ToggleButton playButton = mc.getControlPaneController().getPlayButton(); // 2 Node source = (Node) event.getSource(); Stage stage = (Stage) source.getScene().getWindow(); if (mc.testInet()) { stage.close(); mc.play(webEngine, playButton); } else { stage.close(); MainController.exist = false; } } }); exitButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { Platform.exit(); } }); }}但是它仍然返回NullPointerException。当我尝试仅对ConnectionErrorController中的控制器进行引用时,我遇到了同样的问题。如何从ConnectionErrorController中的控制器正确引用ToggleButton i WebEngine对象?
添加回答
举报
0/150
提交
取消