0
我有一个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;
}
我跑了一个调试器,它只是给出了当返回线运行错误。
写入的return语句不能生成NullPointerException。你能发布完整的堆栈跟踪并指出它们对应的行吗? – davmac