Ich bekomme immer "Exception in thread "main" java.util.NoSuchElementException"

So, ich bin versucht, ein einfaches Programm in Java, das liest eine text-Datei (aus einem Kommandozeilen-argument), und der Benutzer kann überprüfen, um zu sehen, ob eine Nummer, die Sie Eingabe in der text-Datei.

File inputFile = new File(args[0]);
Scanner scanman = new Scanner(inputFile); //Scans the input file
Scanner scanman_2 = new Scanner(System.in); //Scans for keyboard input
int storage[] = new int[30]; //Will be used to store the numbers from the .txt file

for(int i=0; i<storage.length; i++) {
  storage[i]=scanman.nextInt();
  }
System.out.println("WELCOME TO THE NUMERICAL DATABASE"+
                  "\nTO CHECK TO SEE IF YOUR NUMBER IN THE DATABASE"+
                  "\nPLEASE ENTER IT BELOW! TO QUIT: HIT CTRL+Z!");
while(scanman_2.hasNext()){
  int num_store = scanman_2.nextInt();
  boolean alert = false;
  for (int i=0; i<storage.length; i++) {
     if(storage[i]==num_store){
        alert=true;
        }
     }
  if (alert) {
     System.out.println("Yep "+num_store+" is in the database\n");
     }
  else {
     System.out.println("Nope, "+num_store+" is not in the database\n");
     }
  }
System.out.println("See ya!");                
  }
}

Jedesmal, wenn ich versuchen Sie, es auszuführen bekomme ich immer wieder:

Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at Database.main(Database.java:17)

Ich habe ein Programm ähnlich wie diese, und hatte keine Probleme. Weiß jemand, was ich falsch mache?

InformationsquelleAutor Edax | 2014-03-08

Schreibe einen Kommentar