title: Java Scanner No Line Found, Not waiting for user input
body: <p>I am having an issue getting my Scanner object to read user input.  I want the scanner to read user input and save the input to a byte array.</p>
  
  <p>If I use the following code:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class ExamTaker {
      public static void main(String[] args) {
          // Variable Declaration
          char[] studentTest = new char[20];
  
          // Input Setup
          Scanner keyboard = new Scanner(System.in);
  
          // Take the test
          for (int i = 0; i &lt; studentTest.length; i++) {
              System.out.print("\nAnswer " + (i+1) + " : ");
              studentTest[i] = keyboard.nextLine().charAt(0); // The troubled line
          }
      }
  }
  </code></pre>
  
  <p>I get the exception error as follows:</p>
  
  <pre><code>Answer 1 : Exception in thread "main" java.util.NoSuchElementException: No line found
      at java.util.Scanner.nextLine(Unknown Source)
      at ExamTaker.main(ExamTaker.java:14)
  </code></pre>
  
  <p>Having researched via Stack Overflow and Google, I have taken the suggestion to place my troubled line into a try-catch, as follows:</p>
  
  <pre><code>// Take the test
          for (int i = 0; i &lt; studentTest.length; i++) {
              System.out.print("\nAnswer " + (i+1) + " : ");
              try {
                  studentTest[i] = keyboard.nextLine().charAt(0);
              }
              catch (Exception e) {
                  System.out.print("Exception found");
              }
          }
  </code></pre>
  
  <p>However, this still won't produce the desired output for what I believe is an issue with the way I'm using the nextLine() method.  It merely throws the "Exception found" literal in front of each numbered answer.</p>
  
  <p>I have also tried changing the for loop to a do-while loop, and tossing in a keyboard.getChar() in case it wasn't reaching the end of a line, but to no avail.</p>
  
  <p>How do I get the user to input a string in which I take the first character and assign it to my char array in this instance?  Thanks in advance for your help.</p>