i keep getting this one error, and im unsure how to change the code to get rid of this error. nothing seems to work.what would be the way to get rid of this error?
import java.util.*;
import java.io.*;
public class string2 {
public static String getInput(Scanner in) throws IOException {
File dataFile = new File("data.txt");
String input = null;
if (!dataFile.exists()) {
System.out.println("Error");
System.exit(0);
}
return input;
}
public static int getWordCount(String input) throws IOException {
String[] result = input.split(" ");
return result.length;
}
public static void main(String[] args) throws IOException {
String input = getInput(new Scanner(System.in));
int counter = getWordCount(input);
System.out.println("The number of words in this string (" + input + ") are: " + counter);
}
}
xception in thread "main" java.lang.NullPointerException
at string2.getWordCount(string2.java:40)
at string2.main(string2.java:51)