我试图通过比较表中的数据和来自 myframe 的数据来加载到组合框,但是每次我的代码运行时我都会收到以下错误消息:- java.lang.NullPointerException,我也尝试使用向量。请帮助:这是我的数据库类中的代码
public ArrayList allocateStaffcombobox(Allocation aloc) throws SQLException
{
ArrayList<Allocation> vec = new ArrayList<Allocation>();
String sql = "select * from staffsubalocation where SubCode='"+aloc.getSubjCode()+"'";
ResultSet result = stmt.executeQuery(sql);
while (result.next())
{
String staffNo = result.getString("StaffNo");
String subcode=result.getString("SubCode");
System.out.println(staffNo+" "+ subcode);
vec.add(new Allocation(staffNo,subcode));
}
return vec;
}
这是我的java类的代码:
public void loadStaffCombo()
{
try
{
DatabaseManager db = new DatabaseManager();
ArrayList<Allocation> sub=db.allocateStaffcombobox(null);
Staffcombobox.removeAllItems();
// String firsIndex = " ";
for(int x = 0; x< sub.size(); x++)
{
Staffcombobox.addItem( sub.get(x).getStaffNo());
}
}
catch (SQLException ex)
{
Logger.getLogger(ViewSubjectsJInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}