私の問題はadd()
、自分のメソッドを作成したことArrayList
です。
を取得しNullPointerException
ます。add()
次のコードが示すように、クラスにメソッドを実装するにはどうすればよいですか?
コードは次のとおりです。
public class XY{
private List<DictEntry> dict = new ArrayList<DictEntry>();
public void add(String word, int frequency) {
DictEntry neu = new DictEntry(word, frequency);
if (word == null || frequency == 0) {
return;
}
if (!dict.isEmpty()) {
for (int i = 0; i < dict.size(); i++) {
if (dict.get(i).getWord() == word) {
return;
}
}
}
dict.add(neu);
}
}