我將此數據存儲在10x5矩陣中,但是當我到達第一行的4位置時,我遇到了此錯誤“線程中的異常”AWT-EventQueue-0“java.lang.ArrayIndexOutOfBoundsException:5”。我認為錯誤在listPatients[0][counter]中,但我不知道該怎么辦。public class PatientForm extends javax.swing.JFrame { Patient[][] patientList; int counter; public PatientForm() { initComponents(); patientList = new Patient[10][5]; counter = 0; } private void btnasignarActionPerformed(java.awt.event.ActionEvent evt) { if (counter < listPatients.length) { String identification = txtidentification.getText(); String name= txtname.getText(); String lastName = txtlastName.getText(); String eps = txteps.getText(); boolean type = jrbtipo1.isSelected(); String diagnosis = txtdiagnostico.getText(); Patient objPatient = new Patient(identification, name, lastName, eps, type, diagnosis); listPatients[0][counter] = objPatient; counter++; JOptionPane.showMessageDialog(this, "Head" + counter + " Patients."); }else { JOptionPane.showMessageDialog(this, "Error", "Error", JOptionPane.ERROR_MESSAGE); } }}
將數據存儲在多維數組中
慕婉清6462132
2022-08-17 17:26:09