title: java.util.NoSuchElementException - Scanner reading user input
body: <p>I'm new to using Java, but I have some previous experience with C#. The issue I'm having comes with reading user input from console.</p>
  <p>I'm running into the &quot;java.util.NoSuchElementException&quot; error with this portion of code:</p>
  <pre><code>payment = sc.next(); // PromptCustomerPayment function
  </code></pre>
  <p>I have two functions that get user input:</p>
  <ul>
  <li>PromptCustomerQty</li>
  <li>PromptCustomerPayment</li>
  </ul>
  <p>If I don't call PromptCustomerQty then I don't get this error, which leads me to believe I am doing something wrong with scanner. Below is my full code sample. I appreciate any help.</p>
  <pre><code>public static void main (String[] args) {   
      
      // Create a customer
      // Future proofing the possabiltiies of multiple customers
      Customer customer = new Customer(&quot;Will&quot;);
      
      // Create object for each Product
      // (Name,Code,Description,Price)
      // Initalize Qty at 0
      Product Computer = new Product(&quot;Computer&quot;,&quot;PC1003&quot;,&quot;Basic Computer&quot;,399.99); 
      Product Monitor = new Product(&quot;Monitor&quot;,&quot;MN1003&quot;,&quot;LCD Monitor&quot;,99.99);
      Product Printer = new Product(&quot;Printer&quot;,&quot;PR1003x&quot;,&quot;Inkjet Printer&quot;,54.23);
      
      // Define internal variables 
      // ## DONT CHANGE 
      ArrayList&lt;Product&gt; ProductList = new ArrayList&lt;Product&gt;(); // List to store Products
      String formatString = &quot;%-15s %-10s %-20s %-10s %-10s %n&quot;; // Default format for output
  
      // Add objects to list
      ProductList.add(Computer);
      ProductList.add(Monitor);
      ProductList.add(Printer);
      
      // Ask users for quantities 
      PromptCustomerQty(customer, ProductList);
      
      // Ask user for payment method
      PromptCustomerPayment(customer);
      
      // Create the header
      PrintHeader(customer, formatString);
      
      // Create Body
      PrintBody(ProductList, formatString);   
  }
  
  public static void PromptCustomerQty(Customer customer, ArrayList&lt;Product&gt; ProductList) {
      // Initiate a Scanner
      Scanner scan = new Scanner(System.in);
      
      // **** VARIABLES ****
      int qty = 0;
      
      // Greet Customer
      System.out.println(&quot;Hello &quot; + customer.getName());
      
      // Loop through each item and ask for qty desired
      for (Product p : ProductList) {
  
          do {
          // Ask user for qty
          System.out.println(&quot;How many would you like for product: &quot; + p.name);
          System.out.print(&quot;&gt; &quot;);
          
          // Get input and set qty for the object
          qty = scan.nextInt();
          
          }
          while (qty &lt; 0); // Validation
          
          p.setQty(qty); // Set qty for object
          qty = 0; // Reset count
      }
      
      // Cleanup
      scan.close();
  }
  
  public static void PromptCustomerPayment (Customer customer) {
      // Initiate Scanner 
      Scanner sc = new Scanner(System.in);
      
      // Variables
      String payment = &quot;&quot;;
  
      // Prompt User
      do {
      System.out.println(&quot;Would you like to pay in full? [Yes/No]&quot;);
      System.out.print(&quot;&gt; &quot;);
      
      payment = sc.next();
      
      } while ((!payment.toLowerCase().equals(&quot;yes&quot;)) &amp;&amp; (!payment.toLowerCase().equals(&quot;no&quot;)));
      
      // Check/set result
      if (payment.toLowerCase().equals(&quot;yes&quot;)) {
          customer.setPaidInFull(true);
      }
      else {
          customer.setPaidInFull(false);
      }
      
      // Cleanup
      sc.close(); 
  }
  </code></pre>