亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將數據存儲在多維數組中

將數據存儲在多維數組中

慕婉清6462132 2022-08-17 17:26:09
我將此數據存儲在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,這不可用。該數組中任何一行的最后一個索引是 。10x5listPatients[0][5]listPatients[0-9][4]

檢查計數器值,因為它以某種方式為5。請先修復此值或驗證此值,然后再訪問該數組的任何索引。


查看完整回答
反對 回復 2022-08-17
  • 1 回答
  • 0 關注
  • 80 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號