I am trying to search through a file to print out scores. Here is what I have:
while (input.hasNextLine()) {
String record = input.nextLine();
String[] field = record.split(" ");
if(field[1].equals(targetState)) {
System.out.print(field[0] + ": ");
System.out.println(field[2]);
}
}
And the data in file looks like this:
2007,Alabama,252
When I ran this code, I get that java.lang.ArrayIndexOutOfBoundsException error.
I just wonder what is wrong with the code
Thanks