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