title: How to stop NoSuchElementException error from this part of the code?
body: <p>This is a section of my code from a project that is giving an error. I am practicing encapsulation, but, cannot figure out why I am getting this error when I am setting values inside the Array-list.</p>
  
  <p>There are two classes </p>
  
  <p>1) Create_accountant</p>
  
  <p>2) Adminstoreroom</p>
  
  <p>Both of them are under same package: <code>com.admin</code></p>
  
  <pre><code>package com.admin;
  import java.util.InputMismatchException;
  import java.util.Scanner;
  
  class Create_accountant {
  
  Adminstoreroom admin = new Adminstoreroom();
  
  void Creating() {
      System.out.println();
      System.out.println("\t\t\t\t Create New Accoutant");
      System.out.println();
      name();
      pass();
  
  }
  
  void name() {
      Scanner input = new Scanner(System.in);
  
      System.out.println();
      System.out.print("Enter his/her name: \t");
      String name = null;
  
      try {
          admin.setAccName(input.nextLine());
          System.out.println("done");
      }
      catch(InputMismatchException e) {
          System.out.println("Wrong input. Please enter the name again.");
          name();
      }
      catch(Exception e) {
          System.out.println("Here is the main problem " + e);
      }
      admin.setAccName(name);
      input.close();
  }
  
  private void pass() {
      Scanner input = new Scanner(System.in);
  
      System.out.println();
      System.out.print("Enter his/her password: \t");
  
      try {
          admin.setAccPassword(input.nextLine());
      }
      catch(InputMismatchException e) {
          System.out.println("Wrong input. Please enter the password again.");
          pass();
      }
      catch(Exception e) {
          System.out.println("Here is the main problem");
      }
      input.close();
  }
  </code></pre>
  
  <p>The problem is inside the 2 try blocks.</p>
  
  <pre><code>try {
          admin.setAccName(input.nextLine());
          System.out.println("done");
      }
  </code></pre>
  
  <p>Both of the <code>name()</code> and <code>pass()</code> go for the catch(exception e) block. When I run this code, the output from the above try is </p>
  
  <blockquote>
    <p>Here is the main problem <code>java.util.NoSuchElementException: No line found</code></p>
  </blockquote>
  
  <p>The second class</p>
  
  <pre><code>package com.admin;
  
  import java.util.ArrayList;
  
  class Adminstoreroom {
  
  
  //These arrays are used for Storing accountant info in the admin sections
  private static ArrayList&lt;String&gt; accName = new ArrayList&lt;String&gt;(30);
  private static ArrayList&lt;String&gt; accPassword = new ArrayList&lt;String&gt;(30);
  
  //Accountant Names
  public void setAccName(String an) {
      accName.add(an);
  }
  public String getAccName(int i) {
      return accName.get(i);
  }
  
  //Accountant Password
  public void setAccPassword(String ap) {
      accPassword.add(ap);
  }
  public String getAccPassword(int i) {
      return accPassword.get(i);
  }
  </code></pre>