我将此数据存储在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); } }}
1 回答

动漫人物
TA贡献1815条经验 获得超10个赞
矩阵意味着您可以使用数组的索引来自 [0-9][0-4]。这就是您收到索引出站异常的原因。您正在尝试访问 。第二个索引值为 5,这不可用。该数组中任何一行的最后一个索引是 。10x5
listPatients[0][5]
listPatients[0-9][4]
检查计数器值,因为它以某种方式为5。请先修复此值或验证此值,然后再访问该数组的任何索引。
添加回答
举报
0/150
提交
取消