So my code compiles fine, but I get a run-time error
Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenize r.java:332)
at Hw13.main(Hw13.java:36)
What's wrong with my code?import java.util.*; import java.io.*; class Main { public static void main ( String [] args ) throws Exception { Scanner kb = new Scanner ( System.in ); System.out.print("Filename? "); String filename = kb.nextLine(); Scanner sc = new Scanner ( new File ( filename )); StringTokenizer strTokenizer = new StringTokenizer(filename,"."); int chars = 0; int words = 0; int charA = 0; int the = 0; while ( sc.hasNext()) { String s = sc.next(); words++; } while ( strTokenizer.hasMoreTokens()) { if ( strTokenizer.nextToken().equalsIgnoreCase("the")) the++; if ( strTokenizer.nextToken().equalsIgnoreCase("a") || strTokenizer.nextToken().equalsIgnoreCase("an")) charA++; strTokenizer.nextToken(); chars++; } System.out.println("chars " + chars); System.out.println("words " + words); } }