dirnthelord 0 Newbie Poster

Here is the thing. This code segment is supposed to add the Subject Codes for Student each time I change the Student ID from
jcmbDIT combo box. Initialization works well. and after I handled NullPointerException subject codes are loaded into the jcmbSubCode combo box correctly.

private void jcmbDITActionPerformed(java.awt.event.ActionEvent evt) {
        DA da = new DA(); //DA is the class for accessing database (Hibernate)
        Vector sub = da.listStudentSubjects(jcmbDIT.getSelectedItem().toString()); //Get the enrolled subjects into a Vector
        try {
            //Get the data model used by jcmbSubCode , cast it to default model for combo boxes
            DefaultComboBoxModel dcbm = (DefaultComboBoxModel) jcmbSubCode.getModel();
            dcbm.removeAllElements(); //remove all items in this data model
            for(int i=0;i<sub.size();i++) //Fill the combo box with enrolled subject codes by the selected student
            jcmbSubCode.addItem(sub.elementAt(i));
        } catch (Exception e) {
            //JOptionPane.showMessageDialog(null, "An error occured during the operation.", "Error", 0);
        }
    }

Problem is this. At the beginning before I change the Student ID it works well. That is convert subject code and display it in a label. for instance Sub_Code 206 = Probability and Statistics

But if I change the student from jcmbDIT , (and codes are loaded), I can't do the conversion by following code.

private void jcmbSubCodeActionPerformed(java.awt.event.ActionEvent evt) {                                            
        DA da = new DA();
        jlSub.setText(da.getSubject(jcmbSubCode.getSelectedItem().toString()));
}

This code works fine in other occasions.

What has gone wrong? is there any other way to just clear out the jcmbSubCode when i change Student?

Someone please help me out.