打开新阶段时发生JAVAFX加载异常
大家好,我是javafx新手,我一直在开发一个简单的员工应用程序。。。但是当我点击一个按钮打开一个新的舞台时,我会犯下这个痛苦的错误。这是我的密码打开新阶段时发生JAVAFX加载异常,java,javafx,Java,Javafx,大家好,我是javafx新手,我一直在开发一个简单的员工应用程序。。。但是当我点击一个按钮打开一个新的舞台时,我会犯下这个痛苦的错误。这是我的密码 package employee; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; import javafx.stage.Mo
package employee;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.io.IOException;
public class Main extends Application{
private static Stage primaryStage;
private static BorderPane mainLayout;
enter code here
public static void main(String[]args){
launch(args);
}
@Override
public void start(Stage primaryStage) throws IOException {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("Employee App");
showMainView();
showMainItems();
}
private void showMainView() throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("view/MainView.fxml"));
mainLayout = loader.load();
Scene scene = new Scene(mainLayout);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void showMainItems() throws IOException {
FXMLLoader loader;
loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("view/MainItems.fxml"));
BorderPane mainItemsLayout;
mainItemsLayout = loader.load();
mainLayout.setCenter(mainItemsLayout);
}
public static void showElectricalScene() throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("electrical/ElectricalDep.fxml"));
BorderPane electricalLayout = loader.load();
mainLayout.setCenter(electricalLayout);
}
public static void showMechanicalScene() throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("mechanical/MechanicalDep.fxml"));
BorderPane mechanicalLayout = loader.load();
mainLayout.setCenter(mechanicalLayout);
}
public static void showAddButtonStage() throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("view/addNewEmployee.fxml"));
BorderPane addButton = loader.load();
// BorderPane root = (BorderPane) FXMLLoader.load(Main.class.getResource("view/addNewEmployee.fxml"));
Stage addDialogStage= new Stage();
addDialogStage.setTitle("Add New Employee");
addDialogStage.initModality(Modality.WINDOW_MODAL);
addDialogStage.initOwner(primaryStage);
Scene scene= new Scene(addButton);
addDialogStage.setScene(scene);
addDialogStage.showAndWait();
}
}
这里是错误
感谢您的回答。请尝试将资源与完整的软件包一起加载,例如:
loader.setLocation(Main.class.getResource("/employee/view/MainView.fxml"));
错误在您的FXML文件(
addNewEmployee.FXML
)中,该文件似乎为空。谢谢,这正是错误所在。我有一个空的(addNewEmployee.fxml),您可能会发现它通常有助于使用堆栈跟踪来解决问题。
loader.setLocation(Main.class.getResource("/employee/view/MainView.fxml"));