Try following
- Before calling
tokenizer.nextToken()
checktokenizer.hasMoreTokens()
to ensure that there is a token to read
if(tokenizer.hasMoreTokens()) { x = tokenizer.nextToken(); }
- After reading team name(first part) check whether next part is integer if it is, treat it as score, otherwise append it to team name.
homeTeam = tokenizer.nextToken(); String temp = tokenizer.nextToken(); try { homeScore = Integer.parseInt(temp); } catch(Exception e) { //Comes here if temp is not an integer, so temp is second part of name homeTeam = homeTeam + " "+temp; homeScore = Integer.parseInt(tokenizer.nextToken()); } //Whatever the case, if we come here, it means both hometeam and score are assigned. ........... ........... ...........
- Don't forgot to check
tokenizer.hasMoreTokens()
if you are not sure whether there is a token.