i have been given a file full of details and have to extract it and store into different arrays of objects according to its respective column. The tricky thing is, not all lines have the same amount of data. I can read the file, i can split it and everything.
20005,Arsenal,ManU,Arsenal,WestHam,Y,2,3,40000
2006,ManU,Chelsea,ManU,WestHam,N
2007,ManU,Arsenal,ManU,WestHam,Y,1,0,260000
2008,Chelsea,ManU,Chelsea,Swansea,Y,4,0,285630
2009,Chelsea,ManCity,Chelsea,Swansea,N
I can store everything into arrays up to column 6, after that, for some lines, information is not given, thats when i get the error from eclipse. How would i go about fixing that?
Here is my code: (Not posting all of it as this is an assignment and people are probably looking for answers and i dont want to be caught for collusion)
try{
Scanner kd = new Scanner(file);
while(kd.hasNext()){
String data = kd.nextLine();
String [] values = data.split(",");
String year = values[0];
String winningscore= values[6];
i get this error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
at GrandFinal.<init>(GrandFinal.java:19)
at MainClass.main(MainClass.java:11)