java.lang.ArrayIndexOutOfBoundsException:难以找出发生错误的位置

我正在尝试编写一个基本的Java程序,它从Excel电子表格中收集数据并将其存储在一个数组中。 我遇到的问题是我得到ArrayOutOfBoundsexception,但不能看到我的数组的界限以外的地方。 我甚至有意将数组的尺寸设置为比循环终止值大得多:

import java.io.File; import java.io.IOException; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; public class InputArray { public static void main(String[] args) { String[][] InputArray1; int i = 0; int j = 0; InputArray1 = new String[220][220]; try{ Workbook OLE1Shots = Workbook.getWorkbook(new File("C:/Book12.xls")); Sheet inList = OLE1Shots.getSheet(0); for (i = 0; i < 190; i++){ Cell aCell = inList.getCell(i, 0); Cell bCell = inList.getCell(i, 1); String strIn = aCell.getContents(); String strOrd = bCell.getContents(); if (strIn != ""){ InputArray1[0][j] = strIn; InputArray1[1][j] = strOrd; j = j + 1; } } } catch (BiffException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } for (i = 0; i < 190; i++){ System.out.println(InputArray1[0][i]); System.out.println(InputArray1[1][i]); } } } 

我得到的完整信息是:

 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356) at InputArray.main(InputArray.java:29) 

如果有人能弄清楚这里出了什么问题,那将会很棒。 希望它会变成只是我愚蠢。

编辑:

我正在做一些愚蠢的事情。 抛出错误的是事实,我使用的VBA符号的单元格位置(行,列),其中jxl使用(列,行)。 我改变了这些线:

 for (i = 0; i < 190; i++){ Cell aCell = inList.getCell(i, 0); Cell bCell = inList.getCell(i, 1); 

对这些:

 c = inList.getRows(); for (i = 0; i < c; i++){ Cell aCell = inList.getCell(0, i); Cell bCell = inList.getCell(1, i); 

代码现在运行并正确打印出string。 但是,我不断收到消息

 InputArray as localhost contains obsolete methods. The virtual machine was unable to remove all stack frames running old code from the call stack... 

您的variables“i”从0到189,并被传送到从电子表格中读取单元格的方法。 电子表格是否有多行? 请注意,电子表格程序中出现的行并不一定意味着行在电子表格文件中被表示。

这个消息告诉你,如果不是完全的,那是什么错误 – 太大的索引是'2',报告错误的方法是getCell() ,行号告诉你在你的程序中发生了什么。