我正在尝试将场景从登录屏幕切换到我的程序的主屏幕,但每当我尝试在点击登录后切换场景时,我都会收到以下错误。
“线程中的异常”JavaFX Application Thread“java.lang.RuntimeException:java.lang.reflect.InvocationTargetException”
我已经搞乱了我的代码并试图改变一些东西以获得不同的结果,但没有骰子。这是我第一次做GUI,所以任何帮助都会受到赞赏。
package pwmanager;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.event.EventType;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
/**
*
* @author 176878
*/
public class FXMLDocumentController implements Initializable {
@FXML
private Button loginButton;
@FXML
Stage prevStage;
Stage currentStage;
public void setPrevStage(Stage stage){
this.prevStage = stage;
}
@FXML
public void getPrevStage(Stage stage){
this.currentStage = prevStage;
}
@FXML
public void loginButtonAction(ActionEvent event) throws IOException {
System.out.println("You clicked me, logging in!");
setPrevStage(prevStage);
Stage stage = new Stage();
try{
FXMLLoader loader = new FXMLLoader(getClass().getResource("MainScreen.fxml"));
GridPane mainScreen = (GridPane) loader.load();
Scene scene = new Scene(mainScreen);
stage.setScene(scene);
stage.setTitle("Password Manager");
stage.show();
prevStage.hide();
}
catch(IOException e){
System.out.println("Did not load right");
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}