Ниже приведена часть моего кода.Что может быть причиной этого исключения NullPointer?
Я получаю исключение NullPointerException в строке «buckets [i] [h.hashBands (sum, bandRows)]. Add (j);».
В чем может быть причина? Функция
public static void generateBuckets()
{
hash h = new hash();
buckets = new ArrayList[bands][bandRows];
for(int i=0; i<bands; i++)
{
for(int j=0; j<preprocessedList.size(); j++)
{
int[] sum = new int[bandRows];
int a=0;
for(int k=i; k<bands; k++)
{
sum [a] = sigMatrix[k][j];
a++;
}
buckets[i][h.hashBands(sum, bandRows)].add(j);
}
}
В h.hashBands() выглядит следующим образом
public int hashBands(int[] in, int bucketSize)
{
BigInteger hashVal = BigInteger.ZERO;
int k = in.length;
BigInteger base = BigInteger.valueOf(3);
BigInteger size = BigInteger.valueOf(bucketSize);
for (int i = 0; i < in.length; i++)
hashVal = (hashVal.add(BigInteger.valueOf(in[i]).multiply(base.pow(k-i-1))));
hashVal = hashVal.mod(size);
return hashVal.intValue();
}
'buckets [i] [h.hashBands (sum, bandRows)]' возможно null? Как вы инициализируете этот массив? –
Я инициализировал его как buckets = new ArrayList [диапазоны] [bandRows]; – zim