最初と最後を除くすべてのフィールドを取得して JTable に表示する必要がある Access データベースがあります。Object[][] を作成するとすべて問題なく動作しますが、それを返すと NullPointerException が発生します。オブジェクト全体を出力して、データベース内で null 値が存在する可能性がある場所を見つけようとしましたが、それは正常に機能し、null 値はありません。Object[][] を返すと NullPointerException が発生するのはなぜですか?どうすれば修正できますか?
スタック トレース: Exception in thread "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;
}
デバッガーを実行しましたが、リターン行が実行されたときにのみエラーが発生します。