jComboBox+java.lang.StringIndexOutOfBoundsException
In theuser interface, I am selecting the values from4 jComboBox's and concatenating them in theString total. Thetotal is getting printed if I select all the4 jComboBox's.
But sometimes I need to select the values of
1. onejComboBox only
2. twojComboBox only
3. threejComboBox only
But if I don't select alljComboBox's, it's throwing me an error as
Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: 1
My code is:
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"","a","b","c","d","h"}));
String jComboBox1Text=jComboBox1.getSelectedItem().toString();
String jComboBox2Text=jComboBox2.getSelectedItem().toString();
String jComboBox3Text=jComboBox3.getSelectedItem().toString();
String jComboBox4Text=jComboBox4.getSelectedItem().toString();
String total=jComboBox1Text+jComboBox2Text+jComboBox3Text+jComboBox4Text;

