2 回答
TA贡献1826条经验 获得超6个赞
当你调用removeAllItems
它时会触发 actionListenerjComoboBox14
并且在这个阶段它不会有任何 Items 所以getSelected
会返回NULL
改变你if
的
if(jComboBox14.getItemCount() > 0 && (jComboBox14.getSelectedItem().toString().equals("SELECT") | jComboBox14.getSelectedItem().toString().isEmpty())){
TA贡献1874条经验 获得超12个赞
首先。你应该给你的对象变量一个有用的名字:例如:jComboBox13 --> JComboBox comboRoomsType = new JComboBox();或者你喜欢的任何名字。
然后,很高兴看到所有涉及的代码。我看不到你在哪里初始化ResultSetor PreparedStatement;
我猜 NullPointer 在尝试检索值时来自 select 语句。
if(jComboBox13.getSelectedItem().toString().equals("SELECT")){
}else{
try{
String like = jComboBox13.getSelectedItem().toString();
String sql = "Select * From Room_Master RM " +
"inner join Room_Type RT on RM.Room_Type_ID=RT.Room_Type_ID "
+"where Room_Type = '"+like+"'";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
jComboBox14.removeAllItems();
jComboBox14.addItem("SELECT");
//you can also check if there are values first.
while(rs.hasNext()){
rs.next();
String add1 = rs.getString("Room_No");
//You can also use
//String add1 = rs.getInt(number of column of <Room_No> );
jComboBox14.addItem(add1);
}
}catch(Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, e);
}finally {
try {
rs.close();
pst.close();
}catch(Exception e){
}
}
}
添加回答
举报