for (int i=0; i < noOfTextFields; i++) { String value = (String)jComboBox[i].getSelectedItem(); school = new School(textFields[i].getText(), value); try { objectOutputStream.writeObject(school.toString()); } catch (IOException ioe) { JOptionPane.showMessageDialog(this, "There was an IOException", "Error", JOptionPane.ERROR_MESSAGE); } }