次の警告が表示されます
Null passed for nonnull parameter of new java.util.Scanner(Readable) in
model.WordCount.getFile(File).
なぜこれを取得するのですか?また、この警告を取り除くにはどうすればよいですか?方法は次のとおりです。
/**
* Receives and parses input file.
*
* @param the_file The file to be processed.
*/
public void getFile(final File the_file) {
FileReader fr = null;
try {
fr = new FileReader(the_file);
} catch (final FileNotFoundException e) {
e.printStackTrace();
}
Scanner input = null;
String word;
input = new Scanner(fr);
while (input.hasNext()) {
word = input.next();
word = word.toLowerCase().
replaceAll("\\.|\\!|\\,|\\'|\\\"|\\?|\\-|\\(|\\)|\\*|\\$|\\#|\\&|\\~|\\;|\\:", "");
my_first.add(word);
setCounter(getCounter() + 1);
}
input.close();
}
FileReader
エラーを回避するために、をnullに初期化する必要がありました。これが警告のきっかけです。