• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

java.lang.IllegalArgumentException

B

Bretenn

Guest
#1
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
 
B

Bretenn

Guest
#2
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 posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,014
Latest member
sanoravies