sách gpt4 ai đã đi

Ngoại lệ JavaFX

In lại 作者:行者123 更新时间:2023-12-02 05:44:39 41 4
mua khóa gpt4 Nike

我在 JavaFX 异常方面遇到一些问题。我的项目在我的 Eclipse 中运行,但现在我的 friend 也尝试访问该项目。我们已共享并直接保存到保管箱文件夹中。但他根本无法让它发挥作用。他在控制台中收到此错误。真的很感谢一些解释这意味着什么..:)

jun 12, 2014 9:19:37 EM application.Main gotoLogin
SEVERE: null
javafx.fxml.LoadException:
/C:/Users/Administrator/Dropbox/Project%20BlueRift/bin/application/LoginGUI.fxml

at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at application.Main.replaceSceneContent(Main.java:53)
at application.Main.gotoLogin(Main.java:68)
at application.Main.start(Main.java:39)
at com.sun.javafx.application.LauncherImpl$8.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$7.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$6.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(Unknown Source)
at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at application.DBManager.connect(DBManager.java:54)
at controllers.LoginController.initialize(LoginController.java:48)
... 16 more

数据库连接:

package application;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.DatabaseMetaData;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;

import controllers.IReportStatus;

public class DBManager {

private static DBManager INSTANCE;

private final String MYSQL_URL = "jdbc:mysql://213.65.171.115:3306";
private final String MYSQL_DATABASE = "/bluerift";
private final String MYSQL_USER = "test";
private final String MYSQL_PW = "test";
private String CURRENT_USER = null;
private String CURRENT_TIMELINE = null;

private Connection conn = null;
private Statement st = null;
private ResultSet rs = null;
private PreparedStatement preparedStatement = null;;
private DatabaseMetaData dbm = null;

private IReportStatus reportStatus;

private DBManager() {
}

public boolean connect() {
thử {
if (conn != null) {
trả về giá trị đúng;
}

Class.forName("com.mysql.jdbc.Driver");

conn = (Connection) DriverManager.getConnection(MYSQL_URL
+ MYSQL_DATABASE, MYSQL_USER, MYSQL_PW);
st = (Statement) conn.createStatement();
dbm = (DatabaseMetaData) conn.getMetaData();
System.out.println("DevCon: Connected");
trả về giá trị đúng;
}

catch (Exception ex) {
reportStatus.setMsg("Could not reach database.");
conn = null;
st = null;
rs = null;
trả về false;
}
}

public boolean userLogin(String aUserName, String aPassword) {
aUserName = aUserName.trim();

if (aUserName.isEmpty()) {
reportStatus.setMsg("Empty Username");
trả về false;
}

if (aUserName.contains(" ")) {
reportStatus.setMsg("Username can not contain whitespaces");
trả về false;
}

if (aPassword.isEmpty()) {
reportStatus.setMsg("Empty Password");
trả về false;
}

thử {
String query = "SELECT userName,userPassword FROM users";
rs = st.executeQuery(query);

while (rs.next()) {
if (rs.getString("userName").equals(aUserName)) {

if (rs.getString("userPassword").equals(aPassword)) {
System.out.println("DevCon: User "
+ MyUtil.quote(aUserName) + " logged in");
CURRENT_USER = aUserName;

trả về giá trị đúng;
}

else {
reportStatus.setMsg("Wrong Password");
trả về false;
}
}
}

reportStatus.setMsg("Username not found in database");
trả về false;
}

catch (Exception ex) {
reportStatus.setMsg("Could not reach database.");
conn = null;
st = null;
rs = null;
trả về false;
}
}

public boolean userRegister(String aName, String aPassword,
String confirmPassword, String aEmail) {

aEmail = aEmail.trim();
aName = aName.trim();

if (aName.length() < 5 || aName.length() > 25) {
reportStatus
.setMsg("Username has to be between 5 and 25 characters long");
trả về false;
}

if (!MyUtil.isAlphaNumericUs(aName)) {
reportStatus
.setMsg("Username can only contain a-Z, A-Z, 0-9 and _");
trả về false;
}

if (aEmail.isEmpty()) {
reportStatus.setMsg("Email can not be empty");
trả về false;
}

if (!MyUtil.isVaildEmail(aEmail)) {
reportStatus.setMsg("Email incorrect");
trả về false;
}

if (aPassword.length() < 5 || aPassword.length() > 30
|| confirmPassword.length() < 5
|| confirmPassword.length() > 30) {
reportStatus
.setMsg("Password must be between 5 and 30 characters long");
trả về false;
}

if (!aPassword.equals(confirmPassword)) {
reportStatus.setMsg("Password does not match");
trả về false;
}

thử {
String query = "SELECT userName, userEmail FROM users";
rs = st.executeQuery(query);

while (rs.next()) {
if (aName.equals(rs.getString("userName"))) {
reportStatus.setMsg("Username already registred");
trả về false;
}

if (aEmail.equals(rs.getString("userEmail"))) {
reportStatus.setMsg("Email already registred");
trả về false;
}
}

query = "INSERT INTO users (userName, userPassword, userEmail)"
+ " VALUES (?, ?, ?)";

preparedStatement = (PreparedStatement) conn
.prepareStatement(query);
preparedStatement.setString(1, aName);
preparedStatement.setString(2, aPassword);
preparedStatement.setString(3, aEmail);
preparedStatement.execute();
}

catch (Exception ex) {
System.out.println("Error: " + ex);
trả về false;
}

trả về giá trị đúng;
}

public boolean createTimeline(String timelineName) {
timelineName = timelineName.trim();

if (timelineName.length() < 3 || timelineName.length() > 15) {
reportStatus
.setMsg("Name must be between 3 and 15 characters long");
trả về false;
}

System.out.println("timeline name in: " + timelineName);
if (!MyUtil.isAlphaNumeric(timelineName) || timelineName.isEmpty()) {
reportStatus
.setMsg("Invaild timeline name. Allowed symbols are a-z, A-Z and 0-9");
trả về false;
}

if (timelineExists(timelineName)) {

reportStatus.setMsg("Timeline called " + MyUtil.quote(timelineName)
+ " already exists");
trả về false;
}

else {

String query = "CREATE TABLE `bluerift`.`"
+ getCurrentUser()
+ "-"
+ timelineName
+ "` (`id` INT NOT NULL AUTO_INCREMENT,`eventName` VARCHAR(45) NULL,`eventYear` INT NULL,`eventDesc` LONGBLOB NULL,PRIMARY KEY (`id`));";

thử {
st.executeUpdate(query);
} catch (SQLException e) {

e.printStackTrace();
}
}
trả về giá trị đúng;
}

public ObservableList receiveTimelines() {
ObservableList temp = FXCollections.observableArrayList();

thử {
rs = dbm.getTables(null, null, "%", null);
while (rs.next()) {

if (rs.getString(3).contains(getCurrentUser() + "-")) {
temp.add(rs.getString(3).substring(
getCurrentUser().length() + 1));
}
}
} catch (SQLException e) {
e.printStackTrace();
}

return temp;

}

private boolean timelineExists(String t) {

thử {
rs = dbm.getTables(null, null, CURRENT_USER + "-" + t, null);

if (rs.next()) {
trả về giá trị đúng;
}
}

catch (SQLException e) {
e.printStackTrace();
}

trả về false;
}

public void deleteTimeline(String timelineName) {
thử {
String query = "DROP TABLE `bluerift`.`" + getCurrentUser() + "-"
+ timelineName + "`;";
st.executeUpdate(query);
} catch (SQLException e) {
e.printStackTrace();
}
}

public String getCurrentUser() {
if (CURRENT_USER == null) {
return "DevCon: No user online";
}

return CURRENT_USER;
}

public void userLogout() {
if (CURRENT_USER != null) {
System.out.println("DevCon: User " + CURRENT_USER + " logged out");
CURRENT_USER = null;
}

else {
System.out.println("DevCon: No user online");
}
}

public void setReportTo(IReportStatus reportStatus) {
System.out.println("new ReportStatus is: " + reportStatus);
this.reportStatus = reportStatus;
}

public String getCurrentTimeline() {
return CURRENT_TIMELINE;
}

public static DBManager getInstance() {
if (INSTANCE == null) {
INSTANCE = new DBManager();
}
return INSTANCE;
}

}

我真的不知道是什么导致了空指针以及为什么

1 Câu trả lời

异常输出准确地指出了行号:

Caused by: java.lang.NullPointerException
at application.DBManager.connect(DBManager.java:54)

假设问题中的代码与您的生产代码相同,第 54 行包含:

reportStatus.setMsg("Could not reach database.");

reportStatus 可能未初始化,从而导致 NullPointerException.

关于JavaFX 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24206480/

41 4 0
Bài viết được đề xuất: java - JSON 输出不遵循模型中的 JAXB 注释
Bài viết được đề xuất: java - 更改方形文本字段的颜色
Bài viết được đề xuất: java - 如何接收REST服务调用中的输入参数?
Bài viết được đề xuất: java - 不断验证整数
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com