0
我試着通過比較數據輸入表格,並從myframe數據加載到下拉框選擇,但我evreytime代碼運行我收到此錯誤信息: - 顯示java.lang.NullPointerException,我也使用嘗試向量。請幫助:這是從我的數據庫類代碼JComboBox的加載數據使用WHERE子句
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);
}
}
你可以張貼錯誤堆棧跟蹤? – 2013-02-27 14:26:09
你被明確傳遞'null'在聲明中'ArrayList的子= db.allocateStaffcombobox(NULL);''中的方法loadStaffCombo'這肯定給你一個'NullPointerException' –
2013-02-27 14:27:18
我怎樣才能解決這個問題(由不傳遞null在聲明 – user2115653 2013-02-27 14:36:24