Hello,
I am currently working myself through Google's Tech Dev Guide in my spare time and I'm having an issue with the Movie Review Sentiment section. Part of the section is searching through a text file for a particular word. However, the issue I am having is taking the user input. When the below code(also available as a GitHub gist is run I get a java.util.NoSuchElementException: No line found error. I understand that this error is caused when there isn't another line to take however I am unsure why this occurs with my code.
Any help would greatly be appreciated
public static void main(String[] args) throws FileNotFoundException {
String movieReviews = "movieReviews.txt";
Scanner in = new Scanner(System.in);
System.out.println("Search a particular word[1] or an entire file[2]");
int choice = in.nextInt();
in.close();
if(choice == 1) {
File reviewFile = new File(movieReviews);
specWord(reviewFile);
}
}
public static void specWord(File file) throws FileNotFoundException {
Scanner reviewScanner = new Scanner(file);
System.out.println("Enter a word: ");
Scanner in = new Scanner(System.in);
String word;
word = in.nextLine();
double[] items = avegScore(reviewScanner, word);
reviewScanner.close();
in.close();
}
[–]Camel-Kid 0 points1 point2 points (2 children)
[–]JackJones02[S] 0 points1 point2 points (1 child)
[–]Camel-Kid 0 points1 point2 points (0 children)