我有一个 Access 数据库,我需要检索除第一个和最后一个以外的所有字段并将其显示在 JTable 中。当我创建我的 Object[][] 时一切正常,但是当我返回它时,我得到一个 NullPointerException。我试图通过打印整个对象来查找数据库中可能存在空值的位置,但这工作正常并且没有值是空的。为什么返回 Object[][] 会给我一个 NullPointerException,我该如何解决?
堆栈跟踪是:线程“AWT-EventQueue-0”中的异常 java.lang.NullPointerException
public Object [] [] SetTrainingLogTable() throws SQLException
{
DatabaseConnection connection = new DatabaseConnection();
//Retrieves all the data from the TrainingLog table
ResultSet resultset = connection.SelectStatements("SELECT * FROM TrainingLog");
//Retrieves the number of entries
ResultSet numberofworkouts = connection.SelectStatements("SELECT COUNT(*) FROM TrainingLog");
int count = numberofworkouts.getInt(1);
number = count;
String[][] table = new String [count] [6];
//Number to incriment for while loops
int row = 0;
String date = "";
while(row<count)
{
date = resultset.getString(2);
table [row][0] = calculate.RefineDate(date);
table [row][1] = resultset.getString(3);
table [row][2] = resultset.getString(4);
table [row][3] = resultset.getString(5);
table [row][4] = resultset.getString(6);
table [row][5] = resultset.getString(7);
resultset.next();
row++;
}
Object[][] data = table;
connection.close();
return data;
}
我运行了一个调试器,它只在运行返回行时给出错误。