is says at the end No such element exception
Please copy and paste here the FULL text of the error message. It has more information about the error than you show.
Check your data to be sure there are enough tokens for each nextToken() to get one.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
at olmosProyecto.GestionDeHorarios.cargarCurso(GestionDeHorarios.java:44)
That line from the error message tells you which line of your source code (line 44 in GestionDeHorarios.java) threw the error, so you can see what token it was looking for on that line, which should help you identify the error.
ps
Not all lines in the data have 8 tokens, so you can't try to read 8 from every line. Read the first token to see what kind of record it is, then read the correct number of tokens for that record type and create the appropriate object.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
Read the API documentation for the StringTokenizer class. It has methods to test the number of tokens and if there are more available.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
Just a thought...
The best-encapsulated way to implement this may be to have a constructor in each class that takes a StringTokeniser as a parameter - that way all the knowledge about how many fields there are and how to parse and save them is where it should be - in the class itself...
StringTokenizer stknzr = new StringTokenizer(dataRenglon,"_");
String clave = stknzr.nextToken();
switch (clave.charAt(0)) {
case 'P': Profesor profesor = new Profesor(stknzr); break;
//etc
}
...
public Profesor(StringTokenizer stknzr){
nombre = stknzr.nextToken();
dni = stknzr.nextToken();
despacho = stknzr.nextToken();
departamento = stknzr.nextToken();
...
}
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073