title: NoSuchElementException Scanner java
body: <p>I'm getting the below exception in my java project. </p>
  
  <pre><code>Exception in thread "main" java.util.NoSuchElementException
      at java.util.Scanner.throwFor(Unknown Source)
      at java.util.Scanner.next(Unknown Source)
      at com.ooad.ooadfirstassignment.Employee.readData(Employee.java:25)
      at com.ooad.ooadfirstassignment.Salaried.readData(Salaried.java:16)
      at com.ooad.ooadfirstassignment.Factory.&lt;init&gt;(Factory.java:21)
      at com.ooad.ooadfirstassignment.MainClass.main(MainClass.java:25)
  </code></pre>
  
  <p>The Code is as follows :</p>
  
  <p>=====================================================</p>
  
  <pre><code>public class MainClass {
  
      /**
       * @param args
       */
      public static void main(String[] args) throws IOException
      {
          // TODO Auto-generated method stub
          FileInputStream empTextStreamIn = null;
          try
          {
              empTextStreamIn = new FileInputStream("Employee.txt");
          }
          catch(FileNotFoundException fex)
          {
              System.out.println("Employee File not found");
              fex.printStackTrace();
          }
          Factory f = new Factory(empTextStreamIn);
          empTextStreamIn.close();
  
      }
  
  }
  </code></pre>
  
  <p>====================================================================</p>
  
  <pre><code>public class Factory 
  {
      public Factory(FileInputStream empTextStreamIn) 
      {
          // TODO Auto-generated constructor stub
          int empType;
          String EmpID = null,DeptID = null;
          double salary=0;
          Scanner sc = new Scanner(empTextStreamIn);
          while(sc.hasNextLine())
          {
              empType = sc.nextInt();
              switch (empType) 
              {
                  case 1:Salaried salr = new Salaried(empTextStreamIn);
                          salr.readData();
  
                                        System.out.println("EmpType="+empType+"   EmpID="+EmpID+"   DeptID="+DeptID+"   Salary="+salary);
  </code></pre>
  
  <p>The code goes on so this is the main part though.</p>
  
  <h1>Next the Employee Class</h1>
  
  <pre><code>public class Employee 
  {
      String EmpID, DeptID;   //Unique detail for Employee class
  
      protected Scanner sc;
  
      Employee()
      {
  
      }
      public Employee(FileInputStream empTextStreamIn) 
      {
          // TODO Auto-generated constructor stub
          sc = new Scanner(empTextStreamIn);
  
      }
      void readData()
      {
          String EmpID = sc.next();
          String DeptID = sc.next();
      }
  </code></pre>
  
  <h1>}</h1>
  
  <p>Salaried Class</p>
  
  <pre><code>public class Salaried extends Employee
  {
      double salary;  //Unique detail for Salaried class
  
      public Salaried(FileInputStream empTextStreamIn) 
      {
          super(empTextStreamIn);
  
      }
      void readData()
      {
          super.readData();
          salary = sc.nextDouble();
  
  
      }
  
  }
  </code></pre>
  
  <p>Kindly help me where I'm going wrong.</p>