Monday 15 August 2011

java - No Such Element Exception -


I understand such an element exception, but I do not understand what I'm doing wrong. I need to use the tokener so that I can read the toxics like "A-902" or "S-823" and can identify the letter in 0 to determine which department the employee is in. Information.txt is included in this way:

Jane Rivers, A-902, 05/16/2001, 1, 16.25
Bob Cox, S-823, 06/21/1990, 2, 17.50

  import java.util.Scanner; Import java.io * *; Import java.util.StringTokenizer; Create public class {public static zero main (string [] AGR) throws file notfound expression (new file file = "new file" ("notification .ttt"); read scanner file = new scanner (newfile); printwire outfile = new printwriter ("Department.TTT"); string [] employee = new string [9]; while (readFile.hasNext ()) {for (int i = 0; i & lt; employees.length; i ++) {employees [ I] = readFile.nextLine ();}} for (int k = 0; k & lt; employee length; K ++) {StringTokenizer Token = New StringTokenizer (Employee), ","); while (token.hasMoreTokens ()) {outFile.print (token.nextToken ()); if (token.nextToken (). (0) == 'A') {outFile.print (token.nextToken ()) Outfile Print ("Accounting");} Else {if (token.nextToken (). CharAt (0) == 'H' ) {OutFile.print (token.nextToken ()) Outfile Print ("Human Resources");} and {if (token.nextToken (). CharAt (0) == 'P') {outFile.print (token) .nextToken (); Outfile Print ("Production");} Else {if (token.nextToken (). CharAt (0) == 'S') {} outFile.print (token.nextToken ()); OutFile.print ("shipping"); }}}}} ReadFile.close (); OutFile.close (); }}    

You can call token.nextToken () There are many times in your while loop

You should use it only once, and store the result in a temporary variable and use it.

No comments:

Post a Comment