Your problem is when you read the number of employees:
String[] size = in.nextLine().split(":"); //Saltas a la segunda línea
int n = Integer.parseInt(size[1]);
in.nextLine(); //Saltas a la tercera línea
Since if you look at your code in the first line you are already jumping to the second line with the nextLine
method. In your third line of code (of which I copied above) you jump again to the third line so your code starts reading the employees from the third line and if you try to read your employees, the last employee (according to your code) will try to read it in the 5th line, which does not exist.
Using a nextLine
method without saving the value, you should only use it when you use nextInt
, nextDouble
, etc ... that only read a value and leave the cursor on the same line but not when you read the line whole.
I have forgotten how you can solve your error although I think it is quite obvious. Remove your line in.nextLine();
, which jumps to your third line and your code will work without problems.