我已標記行那給我找麻煩的Java數組列表/列表錯誤
private void EditButtonActionPerformed(java.awt.event.ActionEvent evt) {
DefaultListModel PatientListModel =新DefaultListModel();
for (Patient s : PatientList) {
int AccNum = Integer.parseInt(IDTextField.getText());
if (AccNum == s.getAccountNumber()) {
s.setName(NameTextField.getText());
s.setAge(Integer.parseInt(AgeTextField.getText()));
s.setAddress(AddressTextField.getText());
String PatientSex = "";
if (MaleRadioButton.isSelected()) {
PatientSex = "Male";
}
if (FemaleRadioButton.isSelected()) {
PatientSex = "Female";
}
s.setSex(PatientSex);
s.setPhone(PhoneTextField.getText());
ArrayList<PatientCondition> PatientConditions3 = new ArrayList();
===> PatientConditions3 = (ArrayList<PatientCondition>) ConditionsJList.getSelectedValuesList(); //error here
s.setConditionsList(PatientConditions3);
PatientInfoLabel2.setText("Patient Details Updated");
for (Patient f : PatientList) {
PatientListModel.addElement(f.getAccountNumber() + "-" + f.getName());
}
PatientJList.setModel(PatientListModel);
UpdateAllViews();
//
}
}
}
的錯誤是:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.util.Collections$EmptyList cannot be cast to java.util.ArrayList
與問題無關,但您不應該使用大寫啓動變量名,請遵循java指南,這非常重要。 –
@resus,但是,堅持正確的命名約定會更好。它仍然沒有任何錯誤,將停止代碼工作。我只是建議benny閱讀這個http://java.about.com/od/javasyntax/a/nameconventions.htm,因爲使用正確的命名約定在將來維護代碼時將有助於您大展身手。即使你只是搞亂了代碼,開始這樣做也是不錯的做法。 – Popeye