我正在開發(fā)一個用 Java 編碼并與 My SQL 數(shù)據(jù)庫交互的學(xué)校項目。我已經(jīng)進(jìn)入登錄屏幕以確定用戶名和密碼是否正確,如果正確,則轉(zhuǎn)到主屏幕。我現(xiàn)在想做的是跟蹤已登錄的用戶,以便我可以在其他類中引用它。我創(chuàng)建了一個 currentUser 類,其中包含以下內(nèi)容。public class CurrentUser { public String loggedInUser; CurrentUser(String user){ this.loggedInUser = user;} public String getCurrentUser(){ return this.loggedInUser;} public void setCurrentUser(String user){ this.loggedInUser = user;} }在我的登錄應(yīng)用程序中,在確認(rèn)用戶名和密碼后的區(qū)域中,我輸入了以下內(nèi)容。void handleLogIn(javafx.scene.input.MouseEvent event) throws IOException, SQLException {// verify login and send to main screenString userName = username.getText(); String passWord = password.getText();boolean notFound = true;Statement stmt = conn.createStatement();String sqlExecute = "SELECT * FROM user WHERE userName = " + "'" + userName + "'" + " AND password=" + "'" + passWord + "'";Query.makeQuery(sqlExecute);ResultSet result = Query.getResult();while (result.next() && notFound){ //System.out.print(result.getString("userName")); //System.out.print(result.getString("password")); if (userName.equals(result.getString("userName")) && passWord.equals(result.getString("password"))){ notFound = false; Parent root = FXMLLoader.load(getClass().getResource("mainmenu.fxml")); scene = new Scene(root); stage.setScene(scene); stage.show(); currentUser current = new currentUser("userName"); }}userName是指包含剛剛確認(rèn)的userName的變量。我收到錯誤“currentUser 在 currentUser 中不是公開的”。我該如何解決這個問題?任何正確方向或資源的觀點都會非常有幫助!
1 回答

犯罪嫌疑人X
TA貢獻(xiàn)2080條經(jīng)驗 獲得超4個贊
我認(rèn)為問題出在你的構(gòu)造函數(shù)上。也許嘗試將構(gòu)造函數(shù)設(shè)置為公共:
public CurrentUser(String user) { this.loggedInUser = user; }
添加回答
舉報
0/150
提交
取消