title: getting this error -> Exception in thread "main" java.util.InputMismatchException in Java
body: <p>I'm getting the error:</p>
  
  <pre><code>Exception in thread "main" java.util.InputMismatchException
  at java.base/java.util.Scanner.throwFor(Scanner.java:939)
  at java.base/java.util.Scanner.next(Scanner.java:1594)
  at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
  at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
  at com.raghuvamsha.Main.main(Main.java:24)
  </code></pre>
  
  <p>in my program:
  1. Main Class.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Main {
  
  public static void main(String[] args) {
      // write your code here
  
      // Using Scanner for Getting Input from User
      System.out.println("\tMAIN MENU:\n" +
              "\t\t1) Add new member record\n" +
              "\t\t2) Modify existing member record\n" +
              "\t\t3) Delete member record\n" +
              "\t\t4) Display all member records\n" +
              "\t\t5) Search for a particular member record\n" +
              "\t\t6) Exit");
  
      int a = 0;
      while(a!=6) {
  
          Scanner reader = new Scanner(System.in);
  
          a = reader.nextInt();
          System.out.println("You entered integer " + a);
  
          if(a==1){
              AddNewMember anm = new AddNewMember();
              anm.openFile();
              anm.addRecords();
              anm.closeFile();
          }
      }
  
     }
  }
  </code></pre>
  
  <ol start="2">
  <li><p>AddNewMember Class.</p>
  
  <p>public class AddNewMember {</p>
  
  <p>private FileWriter x;
  private Formatter form;</p>
  
  <p>public void openFile(){</p>
  
  <pre><code>try{
      x = new FileWriter("/Users/askeladd/Downloads/animals.dat", true);
      form = new Formatter(x);
  }
  
  catch (Exception e){
      System.out.println("You have an error");
  }
  </code></pre>
  
  <p>}</p>
  
  <p>public void addRecords(){</p>
  
  <pre><code>//Adding Animal Name.
  System.out.println("Please input animal name: ");
  Scanner reader_an = new Scanner(System.in);
  String animal_name = reader_an.next();
  
  //Adding Animal's Owner.
  System.out.println("Please input animal's owner Name: \n");
  System.out.println("First Name: ");
  Scanner reader_aofn = new Scanner(System.in);
  String animal_ofn = reader_aofn.next();
  
  System.out.println("Last Name: ");
  Scanner reader_aoln = new Scanner(System.in);
  String animal_oln = reader_aoln.next();
  
  //Adding species.
  System.out.println("Please input animal species: ");
  Scanner reader_s = new Scanner(System.in);
  String animal_s = reader_s.next();
  
  //Adding Date of Birth.
  System.out.println("Please input animal Date of Birth: ");
  Scanner reader_dob = new Scanner(System.in);
  String animal_dob = reader_dob.next();
  
  //Adding Treatments
  List&lt;String&gt; animal_treatments = new ArrayList&lt;String&gt;();
  System.out.println("Please input treatments: ");
  
  int i = 0;
  Scanner reader_treatments = new Scanner(System.in);
  while (i&lt;10) {
  
  
      String s = reader_treatments.next();
      if (s.equals("q")|| s.equals("Q")) {
  
          break;
      }
      animal_treatments.add(s);
  
      i += 1;
  
  }
  System.out.println(animal_treatments);
  </code></pre>
  
  <p>}</p>
  
  <p>public void closeFile(){
      form.close();
  }</p>
  
  <p>}</p></li>
  </ol>
  
  <p>I have read some posts in StackOverflow regarding the issue, it was mentioned to use next() instead of nextLine() in my code, but still it was not working. Please help me.</p>
  
  <p>Thank you.</p>