NoSuchElementException Error with While Loop : <p>My <strong>readDataFromFile()</strong> method reads text files like this: </p>

<pre><code>Bird    Golden Eagle    Eddie
Mammal  Tiger   Tommy
Mammal  Lion    Leo
Bird    Parrot  Polly
Reptile Cobra   Colin
</code></pre>

<p>With my current <strong><code>while loop</code></strong>, it separates each column: <strong><code>type, species and name</code></strong>.
However the first line has 'Golden Eagle' separated by a <strong><code>space</code></strong> not a <strong><code>tab</code></strong>, so it counts as 2 different substrings, so the output would be <strong><code>'Golden  Eagle  Eddie'</code></strong> instead of <strong><code>'Bird  Golden Eagle  Eddie'</code></strong>.</p>

<p>To try fix this I used the <strong><code>scanner.useDelimiter("\\t");</code></strong> however the output comes out like this:</p>

<pre><code>Golden Eagle  Eddie
Mammal Tiger
Mammal  Lion Leo
Bird
Reptile  Cobra Colin
</code></pre>

<p>with an <strong>ERROR</strong> which highlights this line in my code <strong>'scanner.nextLine();'</strong></p>

<pre><code>java.util.NoSuchElementException: No line found
    at java.util.Scanner.nextLine(Scanner.java:1540)
    at MyZoo.readDataFromFile(MyZoo.java:72)
</code></pre>

<p>My Code:</p>

<pre><code>scanner.useDelimiter("\\t");

      scanner.next();
      while(scanner.hasNextLine())
       {
       String type = scanner.next();
       String species = scanner.next();
       String name = scanner.next();
       System.out.println(type + "  " + species + " " + name);
       scanner.nextLine();
       addAnimal( new Animal(species, name, this) );
       }

      scanner.close();
</code></pre>
