Hello guys, I'm creating this small JAVA programme thats checks for a word in the dictionary but when I run it I get an error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at spellChecker.project1.SpellChecker.main(SpellCheck er.java:10)"
This is my code:
package spellChecker.project1; import java.io.FileReader; import java.util.Scanner; public class SpellChecker{ public static void main(String[] args){ String myFileName = "/Users/Stalin/Desktop/dictionary.txt"; String word= args[0]; boolean found=false; try{ FileReader myFile = new FileReader(myFileName); Scanner scanMyFile = new Scanner(myFile); while( scanMyFile.hasNext() ) { String currWord = scanMyFile.next(); if(currWord.compareTo(word)==0) {found =true; break;} ; } } catch(Exception ex) { System.out.println("exception "+ex.getMessage()+" caught"); } System.out.println(found); } }
Thanks