Java - Scanner throws a NoSuchElementException: No line found -


in program have method choosing account text file. when compilator gets line user enter choice throw exception nosuchelementexception: no line found. please me.

private int chooseacc() throws ioexception {     int choice = -1;     int numofline = 0;     {         if (file.exists() && !file.isdirectory()) {             bufferedreader br = null;             try {                 br = new bufferedreader(new filereader(file));                 while (br.readline() != null) {                     numofline++;                 }              } catch (filenotfoundexception ex) {                 ex.printstacktrace();             } {                 br.close();             }         }          system.out.print("enter option: ");         try {             choice = integer.parseint(sc.nextline()); //stack trace error here         } catch (numberformatexception e) {             system.out.println("error");         }         if (choice < 0 || choice > numofline) {             system.out.println("error");         }     } while (choice < 0 || choice > numofline && numofline == 0);     return choice; } 


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -