2016-09-28 2 views
0

현재 Google 시트 정보 양식을 사용하고 계산을 실행하는 프로그램을 작성 중입니다. "gradle -q run"을 사용하여 프로그램을 실행하고 터미널 내부에서 사용자에게 프롬프트를 표시합니다. 지금 스캐너를 사용하고 있지만 입력을 추가하기를 기다리는 대신 "이름을 입력하십시오 : 예외가 발생했습니다"메인 "java.util.NoSuchElementException"이 표시됩니다. 어떻게 해결합니까?명령 프롬프트에서 사용자에게 메시지 표시

public static void main(String[] args) throws IOException { 
     // Build a new authorized API client service. 
     Sheets service = getSheetsService(); 

     // Prints the names and majors of students in a sample spreadsheet: 
     // https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit 
     String spreadsheetId = "1Pfs-EpysJZXibe1pHiPLEx8cOCC86H5he5ouApejqiE"; 
     String range = "Sheet1!A:E"; 

    // create a scanner so we can read the command-line input 
     Scanner scanner = new Scanner(System.in); 

     // prompt for the user's name 
     System.out.print("Enter your name: "); 

     // get their input as a String 
     String username = scanner.nextLine(); 

     // prompt for their age 
     System.out.print("Enter your age: "); 

     // get the age as an int 
     int age = scanner.nextInt(); 

     System.out.println(String.format("%s, your age is %d", username, age)); 


     ValueRange response = service.spreadsheets().values() 
      .get(spreadsheetId, range) 
      .execute(); 
     List<List<Object>> values = response.getValues(); 
     if (values == null || values.size() == 0) { 
      System.out.println("No data found."); 
     } else { 
      System.out.println("Dominik's Awesome Script Says:"); 
      System.out.println(""); 
      for (List row : values) { 
      // Print columns A and E, which correspond to indices 0 and 4. 
      System.out.printf("%s, %s\n", row.get(0), row.get(4)); 
      } 
     } 
    } 

답변

0

나를 그냥 조건이 거짓가는 계속 것을 볼 수 있지만 입력하는 것이 기다리지 않습니다 그것은 https://www.compilejava.net/

+0

에 나를 위해 일한

while(scanner.hasNextLine()){ username = scanner.nextline(); } 

사용해보십시오. – MickDom