I have this code and I want to get the selected item from jcombobox, but when I run my project, it gives me a copy of the duplicate value of the selected item and java.Lang.NullPointerException Here is the code:
private void jComboBox4ItemStateChanged(java.awt.event.ItemEvent evt) {
if (evt.getStateChange()==ItemEvent.SELECTED){
String a=String.valueOf(jComboBox4.getSelectedItem());
System.out.print(a);
try{
String del2="select distinct PTYPE from Projects inner join project on projects.PNUMBER=(select pro_id from project where pro_name='"+a+"')";
psst=con.prepareStatement(del2);
String td2;
DefaultComboBoxModel mode2 = new DefaultComboBoxModel();
ResultSet rss=psst.executeQuery();
while(rss.next()){
td2=rss.getString("PTYPE");
mode2.addElement(td2);
jComboBox7.setModel(mode2);
}
}
catch(SQLException ex){
JOptionPane.showMessageDialog(null, ex.toString());
}
}
source
share