What happens once you have found the year? The loop will still run until the end of the line, trying to parse things as numbers every time it finds a )
or a -
.
Maybe you should exit the loop once you have found the year.
if(line.charAt(i) == ')' || line.charAt(i) == '-')//get year
{
yr = line.substring(yearStart,i);
year = Integer.parseInt(yr);
break; // year found, no point in looping more
}
Or maybe you should reset the yearStart
index so that the second year can be parsed.
if (line.charAt(i) == '-')
{
// parse first year
yr = line.substring(yearStart,i);
year = Integer.parseInt(yr);
yearStart = i + 1; // reset to parse second year
}
else if (line.charAt(i) == ')')
{
yr = line.substring(yearStart,i);
year = Integer.parseInt(yr);
break; // year found
}