java.lang.IllegalArgumentException

B

Bretenn

Guest
java.lang.IllegalArgumentException: setSelectedIndex: 0 out of bounds
at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:595)
at form.CourseFrmAdd.initComponent(CourseFrmAdd.java:41)
at form.CourseFrmAdd.<init>(CourseFrmAdd.java:30)
at form.Template.addCourseAction(Template.java:1788)
at form.Template.createForm(Template.java:1274)
at form.Template.actionPerformed(Template.java:494)


what does this mean? below is the coding of coursefrmadd.java
 
public class CourseFrmAdd extends CourseFrm implements ActionListener, ItemListener{
private Connection connection;

public CourseFrmAdd(){
}

public CourseFrmAdd(String a, boolean b1, boolean b2, boolean b3, boolean b4, University wsu){
super(a, b1, b2, b3, b4, wsu);
initComponent(this.c);
startConnection1();
getLecturerDetails();
getIntakeDetails();
}

public void initComponent(Container c){
c.remove(pSearchCourse);
txtCourseID.setText("");
txtCourseName.setText("");
cboIntakeID.setSelectedIndex(0);
cboLecturerID.setSelectedIndex(0);
pContentPanel.setBounds(5,5,890,300);
txtCourseID.setEnabled(true);
cmdOptionButton.addActionListener(this);
cmdCancel.addActionListener(this);
cmdClear.addActionListener(this);
cboSearchCourseID.addItemListener(this);
cboLecturerID.addItemListener(this);
cboIntakeID.addItemListener(this);
}

public void actionPerformed(ActionEvent e) {
if (e.getSource() == cmdOptionButton)
addCourseAction();
else if (e.getSource() == cmdCancel)
cancelAction();
else if (e.getSource() == cmdClear)
clearAction();
}

private void startConnection1(){
try {
String url = "jdbc:eek:dbc:eek:op";
String user = "oop";
String password = "abc123";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection(url,user,password);
System.out.println("Connection Successful");
}
catch (ClassNotFoundException cnfex) {
cnfex.printStackTrace();
JOptionPane.showMessageDialog(null,"Database Connection Error",
wsu.getUniversityName(),JOptionPane.ERROR_MESSAGE );
System.exit(1);
}
catch (SQLException sqlex) {
sqlex.printStackTrace();
JOptionPane.showMessageDialog(null,"Database Connection Error",
wsu.getUniversityName(),JOptionPane.ERROR_MESSAGE );
System.exit(1);
}
catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null,"Database Connection Error",
wsu.getUniversityName(),JOptionPane.ERROR_MESSAGE );
System.exit(1);
}
}

private void addCourseAction(){
try{
Statement statement1 = connection.createStatement();
String valid = "SELECT * FROM Course WHERE courseid = '" +
txtCourseID.getText().trim() + "'";
ResultSet rs1 = statement1.executeQuery(valid);
if (rs1.next()){
JOptionPane.showMessageDialog(null, "No Duplicate Course ID.", "Error",
JOptionPane.ERROR_MESSAGE);
rs1.close();
statement1.close();
return;
}

}catch(SQLException sqlex){}
try{
if(validateAction()){
Statement statement = connection.createStatement();
String query = "INSERT INTO Course(courseid,coursename,intakeid,lecturerid) " + "VALUES ('" +
txtCourseID.getText().trim() + "', '" +
txtCourseName.getText().trim() + "', '" +
cboIntakeID.getSelectedItem().toString().trim() + "', '" +
cboLecturerID.getSelectedItem().toString().trim() + "')";
int result = statement.executeUpdate(query);
if (result == 1){
JOptionPane.showMessageDialog(this, "Insertion Success", "Insertion", JOptionPane.INFORMATION_MESSAGE);
}else JOptionPane.showMessageDialog(this, "Insertion Failed");
}

}catch(SQLException sqlex){
sqlex.printStackTrace();
JOptionPane.showMessageDialog(null, sqlex.getMessage());
}catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}

public void itemStateChanged(ItemEvent e) {
if (e.getSource()== cboLecturerID)
getLecturerDetails();
else if (e.getSource() == cboIntakeID)
getIntakeDetails();

}


}


hope u guys can help me...
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,623
Latest member
AndersonLo
Back