0

Hello.

I can't seem to figure out why the following code is producing a NullReferenceException. I have checked, and have confirmed that the arrays are in fact not null, all of the elements contain data. So why does VS think something's null? Thanks for your help.

```
// This line produces the error
NeuralNet net = new NeuralNet(CreateWeightsArray(NETWORK_INPUTS.Length), CreateFunctionsArray());
private Function[][] CreateFunctionsArray() // Functions are Enums
{
// NEURONS_PER_LAYER is an int[]
Function[][] functions = new Function[NEURONS_PER_LAYER.Length][];
for (int x = 0; x < functions.Length; x++)
{
functions[x] = new Function[NEURONS_PER_LAYER[x]];
for (int y = 0; y < functions[x].Length; y++)
functions[x][y] = DEFAULT_FUNCTION; // Set functions to default function.
}
return functions;
}
private double[][][] CreateWeightsArray(int numInputs)
{
double[][][] weights = new double[NEURONS_PER_LAYER.Length][][];
for (int x = 0; x < weights.Length; x++)
{
weights[x] = new double[NEURONS_PER_LAYER[x]][];
for (int y = 0; y < weights[x].Length; y++)
{
if(x == 0)
weights[x][y] = new double[numInputs + 1];
else
weights[x][y] = new double[NEURONS_PER_LAYER[x - 1] + 1];
for (int z = 0; z < weights[x][y].Length; z++) // Cycles through and sets all weights.
weights[x][y][z] = rand.NextDouble();
}
}
return weights;
}
```

*Edited 4 Years Ago by kendaop*