我已經(jīng)閱讀并嘗試了許多相關(guān)問題,最后在這里發(fā)布了一個(gè)問題。我正在嘗試從登錄窗口打開軟件的主窗口。登錄類是具有 main 方法的入口點(diǎn)。一切正常,直到我沒有mainWindowController在mainWindow.fxml文件中聲明。它給loadExceptionjavafx.fxml.LoadException: file:/C:/Users/PIU-PDMA/Documents/GitHub/ExamSystem/dist/run1388756810/ExamSoft.jar!/view/mainWindow.fxml:10這是我loginController的方法(單擊登錄按鈕時(shí)的方法)@FXML void makeLogin(ActionEvent event) { FXMLLoader fXMLLoader; Parent root; Scene scene; try { root = FXMLLoader.load(getClass().getResource("/view/mainWindow.fxml")); Stage stage = new Stage(); stage.setTitle("Main Window"); stage.setScene(new Scene(root)); stage.setMaximized(true); stage.show(); } catch (Exception e) { Logger logger = Logger.getLogger(getClass().getName()); logger.log(Level.SEVERE, "Failed to create new Window.", e); JOptionPane.showMessageDialog(null, "Error "); } }根據(jù)我的研究,如果我們使用getResourcemethod ,我們應(yīng)該使用前導(dǎo)斜線,如果我們使用getClassLoader我們不會(huì)在路徑中使用前導(dǎo)斜線getClass().getResource("/view/login.fxml")); // correct with slash (/)getClass().getClassLoader().getResource("view/login.fxml")); // correct without slash (/)當(dāng)我按下ctlr并單擊 fxml 文件中的控制器鏈接時(shí),它會(huì)將我?guī)У秸_的控制器文件。所以我不明白為什么我會(huì)面臨這個(gè)問題。任何幫助,將不勝感激。這是我的結(jié)構(gòu)控制器類class MainWindowController { @FXML private AnchorPane main_layout;@FXML void pinWindow(ActionEvent event) { Stage s = (Stage) main_layout.getScene().getWindow(); s.setAlwaysOnTop(true); }}
1 回答

RISEBY
TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊
您的MainWindowContoller
課程是package private
(它沒有訪問修飾符)。這意味著您的 FXML 文件無法找到它,因?yàn)樗?code>controller包外無法訪問。
將類聲明public class MainWindowController {
改為。
附帶說明:堆棧跟蹤的頂行很少指向錯(cuò)誤的實(shí)際原因。這通常就是應(yīng)用程序執(zhí)行停止的地方。
您需要在 StackTrace 中查找以“Caused By:”開頭的行才能找到實(shí)際錯(cuò)誤。
添加回答
舉報(bào)
0/150
提交
取消