2017-04-26 6 views
0

포럼에 처음 올 자. 시도했지만 도움이 아무것도 찾을 수 없습니다. 이 코드는 Java 1.7을 사용하는 다른 IDE에서 문제없이 실행했습니다. Eclipse를 사용하고 Java를 1.8으로 업데이트하고 오류가 발생했습니다. "response = input.nextLine();"과 관련된 java.util.NoSuchElementException. 이상한 점은 문자열을 반환하고 정확한 루프 (do/while 패턴 검사)로 코드화 된 다른 함수가 있는데 제대로 작동하는 것 같습니다.자바 do while while 콘솔 입력

static boolean search_again() { 
    String response; 
    //Scanner input = new Scanner(System.in); 
    do { 
     System.out.println("Would you like to search another site? "); 
     Scanner input = new Scanner(System.in); 
     response = input.nextLine(); 
     input.reset();    
    } 
    while(!response.toUpperCase().matches("Y|YE|YES") && !response.toUpperCase().matches("N|NO")); 
    if (response.matches("[nN[oO]?]")) { 
     System.out.println("Goodbye"); 
     return false; 
    } 
    else { 
     System.out.println("OK - search again!"); 
     return true; 
    } 
} 
+0

[answer] (http://stackoverflow.com/questions/36723447/java-util-scanner-throws-nosuchelementexthception-when-application-is-started --with) –

+0

안녕하세요 친구가 방금 코드를 실행했고 나를 위해 잘 작동합니다. 기본 방법을 확인하고 참조하는 방법 search_again() – HelloWorld

+0

고마워요! 내가 몇 가지 테스트를 발견 : http://stackoverflow.com/questions/13042008/java-util-nosuchelementexception-scanner-reading-user-input – Squanchy

답변

0

동일한 입력으로 스캐너를 다시 시작할 수없는 것처럼 보입니다. 스캐너를 글로벌하게 만들었고 다시 작동하는 것으로 보입니다.