gpt4 book ai didi

java - 调用 fillTable() 时出现 NullPointerException 错误

转载 作者:行者123 更新时间:2023-11-29 00:37:19 25 4
gpt4 key购买 nike

<分区>

我似乎无法发现在调用方法 fillTable() 时出现 NullPointerException 错误的位置。 fillTable 是从按钮调用的,它从文本字段中获取字符串。fillTable 旨在通过从处理程序类检索包含数据的 Object[][] 来填充 JTable。

private void fillTable(String dataType, String searchBy)
{
String[] columnName = {"module name", "Workshop %", "Lecture %", "Tutorial %", "Average %"};
if(searchBy.startsWith("@"))
{
tableModel.setDataVector(pLSHand.gIStudData(dataType, searchBy), columnName);
table.setModel(tableModel);
}
else
{
tableModel.setDataVector(pLSHand.gNStudData(dataType, searchBy), columnName);
table.setModel(tableModel);
}
table.repaint();
}

按钮:

String searchBy = (String)textField.getText();
if(!searchBy.isEmpty())
{
fillTable("Year",searchBy);
}
else
{

}

Handler类中的方法

public Object[][] gIStudData(String dType, String studID)
{

String rQuery = "SELECT * FROM StudAttYear WHERE studentID = '"+ studID +"'";
data = new Object[1][5];

if(dType.equalsIgnoreCase("Semester"))
{
rQuery = "SELECT * FROM StudAttSem WHERE studentID = '"+ studID +"'";
data = new Object[2][5];
}
else if(dType.equalsIgnoreCase("Year"))
{
rQuery = "SELECT * FROM StudAttYear WHERE studentID = '"+ studID +"'";
data = new Object[1][5];
}
else if(dType.equalsIgnoreCase("Week"))
{
rQuery = "SELECT * FROM StudAttWeek WHERE studentID = '"+ studID +"' AND number = '"+ weekNo +"'";
data = new Object[12][5];
}

try{
Class.forName(DRIVER_CLASS);

connection = DriverManager.getConnection( url,"agile", "adila");
statement = connection.createStatement();
results = statement.executeQuery(rQuery);
int i=0;
while(results.next())
{
data[i][0] = results.getString("module");
data[i][1] = results.getString("workshop%");
data[i][2] = results.getString("tutroial%");
data[i][3] = results.getString("lecture%");
data[i][4] = results.getString("avg%");
i++;
}
results.close();
statement.close();
connection.close();
} catch (SQLException sqlException) {
sqlException.printStackTrace();
System.exit(1);
}catch(Exception exception) {
System.err.println("An error happened");
System.exit(1);
}
return data;
}

在其他类(class)中使用相同的技术,它们似乎有效。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com