Trying to handle an exception. Using an If statement at the recommendation of cricket_007 who has been incredibly helpful! However, still struggling through it. Basically, answering the first string question in my gui, and then incrementing the index counter to get the next question. after the user answers the 7th question, I want to end the method, however I just get the outOfBounds exception. I have tried
if (questionIndex > questions.size()) if (questionsIndex > (questions.size()-1)
and have tried writing it the other way where, if the index is less than the size, ask the questions...and else display "done!" and then implement a "results()" method.
protected void calcPersonnelRisk() {
if(questionIndex >(questions.size()-1)){
message.setText("Done");
System.exit(0);
}
//do closing action methods, display total Personnel Risk , end program
else{
yesButton.setVisible(false);
noButton.setVisible(false);
message.setFont(new Font("Tahoma", Font.BOLD, 14));
message.setText(questions.get(questionIndex++));
enterButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int r= Integer.parseInt(textField.getText().trim());
responses.add(r);
textField.setText("");
message.setText(questions.get(questionIndex++));
}});
}
}//end calcPersonnelRisk