クラスの配列を書く正しい方法が見つからないようです。この形式では、コンパイル時にエラーはスローされませんが、配列/クラスを使用しようとするとエラーが発生します。クラスの配列はHashTableという名前のクラスにあり(割り当てのために独自に作成する必要があります)、以下のコードでテストしています。
theHashTable.insert("aa", "ab");
HashTableクラスは次のとおりです。
編集:Aniketが指摘したように、fileNamesは初期化されていませんでした。以下でこれを修正しましたが、同じエラーが発生します。
private class HashTable {
private class Value {
ArrayList<String> fileNames;
String word;
Value() {
fileNames = new ArrayList<String>();
}
}
private int currentSize = 101;
private Value[] items;
private HashTable() {
items = new Value[currentSize];
for (int i = 0; i < currentSize; i++) items[i] = new Value();
}
private int hash(String in) {
int out = 0;
for (int i = 0; i < in.length(); i++) out += 37*out+in.charAt(i);
out %= currentSize;
if (out < 0) out += currentSize;
return out;
}
public void insert(String inW, String inF) {
int index = hash(inW);
index = 0;
if (items[index].word.length() == 0) {
items[index].word = inW;
items[index].fileNames.add(inF);
}
else if (items[index].word.compareTo(inW) == 0) items[index].fileNames.add(inF);
else System.out.println("Collision");
}
}