Java 第二个窗口不会用fxml打开,只会用空fxml打开
Login.JavaJava 第二个窗口不会用fxml打开,只会用空fxml打开,java,javafx,fxml,Java,Javafx,Fxml,Login.Java package Login; public class Login extends Application{ @Override public void start(Stage stage)throws Exception{ Parent root = (Parent) FXMLLoader.load(getClass().getResource("Login.fxml")); Scene scene = new Scene(root); s
package Login;
public class Login extends Application{
@Override
public void start(Stage stage)throws Exception{
Parent root = (Parent) FXMLLoader.load(getClass().getResource("Login.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Library Management System");
stage.show();}
public static void main(String[] args){
launch(args);} }
LoginController.java
package Login;
public class LoginController implements Initializable {
Librarian l1=new Librarian();
@FXML
private JFXTextField username;
@FXML
private JFXPasswordField password;
@FXML
private JFXButton Loginbutton;
@FXML
private JFXButton CancelButton;
@Override
public void initialize(URL url, ResourceBundle rb) {
}
@FXML
private void LibrarianLogin(ActionEvent event) throws SQLException {
if(l1.isLogin(username.getText(),password.getText())){
Stage stage = (Stage) this.Loginbutton.getScene().getWindow();
stage.close();
adminLogin();
}
}
@FXML
private void handleCancelBtnAction(ActionEvent event) {
}
public void adminLogin()
{
try{
Stage adminstage = new Stage();
FXMLLoader adminLoader = new FXMLLoader();
Pane adminroot = (Pane)adminLoader.load(getClass().getResource("/Librarian/admin.fxml").openStream());
AdminController adminController = (AdminController)adminLoader.getController();
Scene scene =new Scene(adminroot);
adminstage.setScene(scene);
adminstage.setTitle("Admin Dashboard");
adminstage.show();
}
catch (IOException e){
}
}
}
每次我按下登录按钮时都会发生错误!我不知道该怎么办!!!
当我将admin.fxml替换为空的fxml时,当我单击登录按钮时,会出现另一个窗口!!
我没有任何错误,但有以下警告:
Apr 21, 2018 1:38:07 AM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 9.0.1 by JavaFX
runtime of version 8.0.161
Apr 21, 2018 1:38:12 AM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 9.0.1 by JavaFX
runtime of version 8.0.161
. 在您的情况下,您可能需要SceneBuilder 8。如果您没有用一个简单地忽略异常的
try catch
来包围块,那么您可能会得到一个错误。顺便说一句:adminLoader.getController()
总是返回null
,因为您正在使用静态方法加载fxml。@fabian我不明白您的意思!当我加载一个空的fxml时,它加载得很好!!但是当我放置一些文本框和一些标签时,它不会加载,也不会给我一个提示error@fabian以下是github链接: