Monday, 19 August 2013

Java Debugging arrayoutofbound exception

Java Debugging arrayoutofbound exception

I am getting Exception in thread "main"
java.lang.ArrayIndexOutOfBoundsException in the line
System.out.println(lineArray[lineArray.length-m]);
while ((strLine = in.readLine()) != null) {
String[] lineArray = strLine.split("");
if (lineArray.length > 0) {
int m = Integer.parseInt(lineArray[lineArray.length-1]);
strLine = strLine.substring(0, strLine.length()-1);
lineArray = strLine.split(" ");
if (lineArray.length - m > 0)
System.out.println(lineArray.length-m);
System.out.println(lineArray[lineArray.length-m]);
}
}

No comments:

Post a Comment