title: Getting an error while trying to read a .txt file
body: <p><strong>The Error is not in the while condition</strong></p>
  
  <p>I load a file (the file contains three columns of numbers separated by tab) and  I get this error : </p>
  
  <p>java.util.NoSuchElementExceptionat java.util.Scanner.throwFor(Unknown Source)at java.util.Scanner.next(Unknown Source)at webscience.Main.countTimesListened(Main.java:43)at webscience.Main.main(Main.java:21)</p>
  
  <pre><code>System.out.println ("Program Starts");
  
      File timesListened = Loader.loadFile();
      countTimesListened(timesListened);
  
  }
  
  public static void countTimesListened (File file) throws FileNotFoundException
  {
      Scanner sc;
  
      UserList userList = new UserList();
      TimesListened timesListened = new TimesListened();
  
      try
      {
          sc = new Scanner (file);
          sc.useDelimiter("\\t");
  
          while (sc.hasNextLine() &amp;&amp; sc.nextLine() != "")
          {
              sc.reset();
  
              String userID = sc.next();
              String artistID = sc.next();
              String weight = sc.next();
  
              userID = userID.replaceAll("\\t", "");
              artistID = artistID.replaceAll("\\t", "");
              weight = weight.replaceAll("\\t", "");
  
              User user = new User (userID);
              Artist artist = new Artist (artistID);
              user.listensTo(artist, weight);
  
              if (!userList.userExists(user))
                  userList.addUser(user);
  
  
              int num = Integer.parseInt(weight);
  
              if (!timesListened.artistExists(artistID))
                  timesListened.addArtistWeight(artistID, num);
              else
                  timesListened.increaseArtistWeight(artistID, num);
              System.out.print(userID + artistID + weight);
  
          }
          sc.close();
      } catch (FileNotFoundException e)
      {
          e.printStackTrace();
      }
      catch (NoSuchElementException e)
      {
          e.printStackTrace();
      }
  
      File outputFile = new File ("user_artists.txt");
      FileOutputStream fos = new FileOutputStream(outputFile);
      PrintStream ps = new PrintStream(fos);
      System.setOut(ps);
      System.out.println(timesListened.toString());
  </code></pre>