java.util.NoSuchElementException: No line found

前端 未结 6 746
失恋的感觉
失恋的感觉 2020-11-22 10:17

I got an run time exception in my program while I am reading a file through a Scanner.

java.util.NoSuchElementException: No line found     
   at java.util         


        
6条回答
  •  遇见更好的自我
    2020-11-22 10:46

    I also encounter with that problem. In my case the problem was that i closed the scanner inside one of the funcs..

    public class Main 
    {
    	public static void main(String[] args) 
    	{
    		Scanner menu = new Scanner(System.in);
            boolean exit = new Boolean(false);
        while(!exit){
    		String choose = menu.nextLine();
            Part1 t=new Part1()
            t.start();
    	    System.out.println("Noooooo Come back!!!"+choose);
    		}
    	menu.close();
    	}
    }
    
    public class Part1 extends Thread 
    {
    public void run()
      { 
         Scanner s = new Scanner(System.in);
         String st = s.nextLine();
         System.out.print("bllaaaaaaa\n"+st);
         s.close();
    	}
    }
    
    		 

    The code above made the same exaption, the solution was to close the scanner only once at the main.

提交回复
热议问题