this is a school assignment
i keep gettng a runtime error that i frankly have no idea how to fix. my output is as follows:
[Session started at 2009-04-13 07:01:57 -0400.]
Competitors
****************
****************
(Option 1) - Create new Sport Stacker
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1471)
at Project8Driver.menuSwitch(Project8Driver.java:6
at Project8Driver.main(Project8Driver.java:54)
The Debugger has exited with status 1.The Debugger has exited with status 1.
i have a heiracrchy of classes as follows: competitor (super parent class)-->speller, sportstacker, trackathlete (trackathlete has two subclasses runner and thrower
the code that generates the error is:
Code:import java.util.Scanner; import java.io.BufferedReader; import java.io.*; public class Project8Driver { public static void main( String[] args ) throws IOException { /*String fileName = ""; //contains the file name of the input file boolean event = true; while (event == true){ //checks if the args[] array contains anything if (args.length > 0) { String file = args[0]; fileName = file; event = false; } else { System.out.println("Please input a file name as a command-line arguement."); } }*/ //create file scanner Scanner fileScan = null; fileScan = new Scanner(new BufferedReader( new FileReader( "P8input.txt" )) ); //scanner for each line //Scanner line = new Scanner( fileScan.nextLine() ); //create competitor array Competitor comp[] = new Competitor[20]; //initialize input choice int inputChoice = 0; //go through input as long as inputs are available while( fileScan.hasNext() && inputChoice != 6) { Scanner line = new Scanner( fileScan.nextLine() ); inputChoice = line.nextInt(); menuSwitch( inputChoice, comp, line); } } /********************************************************************************* switch statement that handles competition inputs *********************************************************************************/ public static void menuSwitch( int choice, Competitor comp[], Scanner line) { switch( choice ) { //Create new SportStacker case 1: System.out.println("(Option 1) - Create new Sport Stacker"); String name = line.nextLine(); String birthplace = line.nextLine(); String gender = line.nextLine(); String age = line.nextLine(); int age1 = Integer.parseInt(age); String bestCompFinish = line.nextLine(); int bestCompFinish1 = Integer.parseInt(bestCompFinish); String numTimesRecorded = line.nextLine(); int numTimesRecorded1 = Integer.parseInt(numTimesRecorded); String ID = line.nextLine(); int ID1 = Integer.parseInt(ID); String regionNumber = line.nextLine(); int regionNumber1 = Integer.parseInt(regionNumber); String three33 = line.nextLine(); boolean event333; if (three33.equalsIgnoreCase("yes")) event333 = true; else event333 = false; String three63 = line.nextLine(); boolean event363; if (three63.equalsIgnoreCase("no")) event363 = true; else event363 = false; comp[0] = new SportStacker(name, birthplace, gender, age1, bestCompFinish1, numTimesRecorded1, ID1, event333, event363, regionNumber1 ); break; //Create new Speller case 2: System.out.println("(Option 1) - Create new Speller"); name = line.nextLine(); birthplace = line.nextLine(); gender = line.nextLine(); age = line.nextLine(); age1 = Integer.parseInt(age); bestCompFinish = line.nextLine(); bestCompFinish1 = Integer.parseInt(bestCompFinish); regionNumber = line.nextLine(); regionNumber1 = Integer.parseInt(regionNumber); String school = line.nextLine(); comp[1] = new Speller(name, birthplace, gender, age1, bestCompFinish1, school, regionNumber1); break; //Create new Thrower case 3: System.out.println("(Option 1) - Create new Thrower"); name = line.nextLine(); birthplace = line.nextLine(); gender = line.nextLine(); age = line.nextLine(); age1 = Integer.parseInt(age); bestCompFinish = line.nextLine(); bestCompFinish1 = Integer.parseInt(bestCompFinish); String ageGroup = line.nextLine(); String bibNumber = line.nextLine(); int bibNumber1 = Integer.parseInt(bibNumber); String bestEvent = line.nextLine(); String bestThrow = line.nextLine(); double bestThrow1 = Double.parseDouble(bestThrow); comp[2] = new Thrower(name, birthplace, gender, age1, bestCompFinish1, ageGroup, bibNumber1, bestEvent, bestThrow1); break; //Create new Runner case 4: System.out.println("(Option 1) - Create new Runner"); name = line.nextLine(); birthplace = line.nextLine(); gender = line.nextLine(); age = line.nextLine(); age1 = Integer.parseInt(age); bestCompFinish = line.nextLine(); bestCompFinish1 = Integer.parseInt(bestCompFinish); ageGroup = line.nextLine(); bibNumber = line.nextLine(); bibNumber1 = Integer.parseInt(bibNumber); String distance = line.nextLine(); int distance1 = Integer.parseInt(distance); String bestTime = line.nextLine(); comp[3] = new Runner(name, birthplace, gender, age1, bestCompFinish1, ageGroup, bibNumber1, distance1, bestTime); break; //Print Competitor Information case 5: System.out.println("Competitors\n****************"); try { for (int i = 0; i < 4; i++){ comp[i].String(); System.out.println(); } } catch (Exception e) {} System.out.println("****************\n"); break; case 6: System.out.println("Goodbye"); break; //if invalid choice default: System.out.println("\nSorry, invalid choice"); } } }
the input file (with comments) that this comes from looks like this:
Code:5 //print out competitors info 1 //add sport stacker John Smith //get competitor name New York, NY //get competitor birthplace Male //get competitor gender 16 //get competitor age 4 //get competitor best competition finish 3 //get sport stacker number of times recorded 638 //get sport stacker ID 12 //get sport stacker region number yes //get sport stacker T/F for event 3-3-3 no //get sport stacker T/F for event 3-6-3 2 //add speller Pat Jones //get competitor name Los Angeles, CA //get competitor birthplace Female //get competitor gender 14 //get competitor age 33 //get competitor best competition finish 19 //get speller region number Washington High School //get speller school 3 //add thrower Gina Toms //get competitor name Dallas, TX //get competitor birthplace Female //get competitor gender 22 //get competitor age 1 //get competitor best competition finish 20 - 25 //get thrower age group 112 //get thrower bib number Discus //get thrower best event 156.7 //get thrower best distance 4 //add runner Logan James //get competitor name Fort Worth, TX //get competitor birthplace Male //get competitor gender 17 //get competitor age 3 //get competitor best competition finish 15 - 18 //get runner age group 334 //get runner bib number 1500 //get runner best distance 00:04:22 //get runner best time 5 //print out competitors info 6 //quit





Reply With Quote
