How to read a java.util.InputMismatchException stack trace
<p>I am struggling to read this stack trace exception below. I wonder If you could help me?</p>

<p>I don't understand any of the numbers in the code (like the number 74, 2119 and 2160, what do they represent in this exception? Quite literally, I need to know which line of my code is causing problems so that I can resolve it. Please help.</p>

<p>Here below is my stack trace, and beneath it is the java code I am trying to resolve alongside a sample input file which came with the task.</p>

<pre><code>java.util.InputMismatchException
  in java.util.Scanner.throwFor(Scanner.java:909)
  in java.util.Scanner.next(Scanner.java:1530)
  in java.util.Scanner.nextInt(Scanner.java:2160)
  in java.util.Scanner.nextInt(Scanner.java:2119)
  in League.loadLeague(League.java:74)
  in (Workspace:1)
</code></pre>

<p>And here, below is my Java code with the method <code>loadLeague</code> which is causing me a lot of headache!</p>

<pre><code>import java.io.*;
import java.util.*;

/**  
 * Class League - An instance of this class represents the teams in a
 * football (or similar) league. It provides a class method for creating
 * a new instance of League by reading the data for the teams from a CSV
 * file.
 * 
 * @author Lewis Jones 
 * @version 1.0
 */

public class League
{
   /* instance variables */
   private String name;  // The name of the league
   private Team[] teams; // An array to hold the teams in the league

   /**
    * Constructor for objects of class League. It sets the name of the league
    * to the String object provided as the first argument and initialises teams
    * to an array of the size provided as the second argument. This constructor 
    * is private as it is intended for use only by the class method loadLeague().
    */
   private League(String aName, int size)
   {
      super();
      this.name = aName;
      this.teams = new Team[size];
   }

   /* class method */
   /**
    * This method creates a new League object by reading the required details from
    * a CSV file. The file must be organised as follows:
    *     name(String), number of teams (int)
    *     team name(String), won(int), drawn(int), lost(int), for(int), against    (int)
    *        and so on for each team
    * Having created the new League object the method should create all the Team 
    * objects (using the data in the file to set their attributes) and add them 
    * to the teams array.
    */
   public static League loadLeague()
   {
      League theLeague = null;
      String pathname = OUFileChooser.getFilename();
      File aFile = new File(pathname);
      Scanner bufferedScanner = null;

      try
      {
         String leagueName;
         int numberOfTeams;

         String teamName;
         int won;
         int drawn;
         int lost;
         int goalsFor;
         int goalsAgainst;
         Scanner lineScanner;
         String currentLine;
         bufferedScanner = new Scanner(new BufferedReader(new FileReader (aFile)));    

         while (bufferedScanner.hasNextLine())
         {
            currentLine = bufferedScanner.nextLine();
            lineScanner = new Scanner(currentLine);
            lineScanner.useDelimiter(",");

            leagueName = bufferedScanner.next();
            numberOfTeams = bufferedScanner.nextInt();

            teamName = bufferedScanner.next();
            won = lineScanner.nextInt();
            drawn = lineScanner.nextInt();
            lost = lineScanner.nextInt();
            goalsFor = lineScanner.nextInt();
            goalsAgainst = lineScanner.nextInt();

            Team aTeam = new Team(lineScanner.next());
            aTeam.setWon(lineScanner.nextInt());
            aTeam.setDrawn(lineScanner.nextInt());
            aTeam.setLost(lineScanner.nextInt());
            aTeam.setGoalsFor(lineScanner.nextInt());
            aTeam.setGoalsAgainst(lineScanner.nextInt());
            Team[] teams = new Team[numberOfTeams];
            teams[numberOfTeams] = aTeam;
            numberOfTeams++;
            theLeague = new League(leagueName, numberOfTeams);
         }
      }  
      catch (Exception anException)
      {
         System.out.println("Error: " + anException);
      }
      finally
      {
         try
         {
            bufferedScanner.close();
         }
         catch (Exception anException)
         {
            System.out.println("Error: " + anException);
         }
      }
      return theLeague;
   }

   /* instance methods */

   /**
    * Displays the league table in tabular format to the standard output
    */
   public void display()
   {
      System.out.println(this.name);
      System.out.format("%20s %2s %2s %2s %2s %2s %2s %    2s\n","","P","W","L","D","F","A","Pt");
      for (Team eachTeam : this.teams)
      {
         System.out.format("%20s %2d %2d %2d %2d %2d %2d %2d\n",
                       eachTeam.getName(), eachTeam.getPlayed(), 
                       eachTeam.getWon(), eachTeam.getDrawn(), 
                       eachTeam.getLost(),eachTeam.getGoalsFor(), 
                       eachTeam.getGoalsAgainst(), eachTeam.getPoints());        
      }
   }

   /**
    * Arrange the elements of teams in their natural order. This will only
    * work if a natural order has been defined for the class Team.
    */
   public void sort()
   {
      // to be written later...
   }
}
</code></pre>

<p>And below is the sample (file) input which the program is supposed to read into:</p>

<pre><code>Scottish League Division 1,10
Airdrie United ,3,2,11,14,25
Clyde          ,5,7,4,21,17
Dundee         ,7,2,7,21,18
Gretna         ,10,3,3,43,20
Hamilton Acas  ,7,5,4,19,20
Livingstone    ,6,6,4,21,15
Partick Thistle,8,4,4,25,29
Queen of South ,3,3,10,11,31
Ross County    ,4,4,8,14,24
St Johnstone   ,6,6,4,26,16
</code></pre>

<p>I have really struggled with this task for nearly a week now! I hope someone out there comes to my rescue as it's really getting on my skin now. Please help. Any tips to pinpoint which code I'm writing wrongly would be so much appreciated.</p>

<p>Thank you guys,</p>

<p>Lew.</p>
