ArrayIndexOutOfBoundsException
So far, my loop will print the first element and then it errors out. Any suggestions would be great.
Code java:
public class Test {
/**
* @param args
*/
public static void main(String[] args)
{
Person a = new Staff(27, "Smith", "Gary", "Professor");
Person b = new Staff(12, "Doe", "Jane"," Professor");
Person c = new Staff(6, "Anderson", "John", "Professor");
Person d = new Student(145, "Bee", "Corey", "Senior", "AMCS", "CS-250");
Person array[][] = {{a}, {b}, {c}, {d}};
for(int i=0; i<array.length; i++)
{
for(int j=0; i<array[i].length; j++)
{
System.out.print(array[i][j]); //java.lang.ArrayIndexOutOfBoundsException: 1
}
System.out.println();
}
}
}
Re: ArrayIndexOutOfBoundsException
Code :
for(int j=0; i<array[i].length; j++)
should be:
Code :
for(int j=0; [b]j[/b]<array[i].length; j++)
You accidentally put an i instead of a j in your condition. Fairly simple and understandable mistake.
Re: ArrayIndexOutOfBoundsException
Yikes, can't believe i didn't catch that. Thanks!