本文介绍了ArrayIndexOutOfBoundsException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){ String Temp = jComboBox1.getSelectedItem()。toString (); testcomm.TestForm。 WriteParamToPic (" c" + Temp); } public static void WriteParamToPic(String ParamIn) { char [] WriteParam = new char [4]; byte [] FinalWriteParam = new byte [4]; WriteParam = ParamIn.toCharArray(); for(int i = 0; i< 4; i ++){ FinalWriteParam [i] =(byte)WriteParam [i]; Comm.PutPointerData(FinalWriteParam,4); } } 我拥有: jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String [] {" 30"," 50"})); 我得到nex err或者: java.lang.ArrayIndexOutOfBoundsException 我必须为WriteParamToPic配置参数吗? 我已经托盘来更改 WriteParamToPic 中的数组数量,但它会返回其他错误。 谢谢private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String Temp = jComboBox1.getSelectedItem().toString(); testcomm.TestForm.WriteParamToPic("c"+Temp); } public static void WriteParamToPic(String ParamIn) { char [] WriteParam = new char[4]; byte [] FinalWriteParam = new byte[4]; WriteParam = ParamIn.toCharArray(); for(int i=0; i<4; i++){ FinalWriteParam[i] = (byte) WriteParam[i]; Comm.PutPointerData(FinalWriteParam,4); } } I have:jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {"30", "50" })); i get nex error: java.lang.ArrayIndexOutOfBoundsException Hove must i configure argument for WriteParamToPic?I have trayed to change number of arrays in WriteParamToPic, but it returns me other errors. Thank you推荐答案 FinalWriteParam [i] =(byte)WriteParam [i]; 此时WriteParam比FinalWriteParam长,因为 FinalWriteParam[i] = (byte) WriteParam[i];At this point WriteParam is longer than FinalWriteParam because 展开 | 选择 | Wrap | 行号 展开 | 选择 | Wrap | 行号 展开 | 选择 | Wrap | 行号 这篇关于ArrayIndexOutOfBoundsException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-18 13:48