Reputation: 1650
I have defined the following class:
public class PerceptronNetwork : NetworkBase
{
Neuron perceptron { get; set; }
public PerceptronTrainer trainingMethod;
public PerceptronNetwork(Neuron aNeuron)
{
this.perceptron = aNeuron;
}
public double train(TrainingTemplate trainingTemplate, int extMaxGenerations)
{
// This is simple but the ideea is suposed to be that in larger networks here
// I do a foreach over the neurons
double error = this.trainingMethod.trainNetwork(trainingTemplate, perceptron,
extMaxGenerations);
return error;
}
}
Whenever I try to use the train method from my main function I get the error
Object reference not set to an instance of an object.
pointing to the perceptron
object.
Despite that when I hover over every object in the function call trainingTemplate, perceptron and extMaxGenerations they all seem to be pointing to proper values.
Did I declare or instantiate them wrong in some way ?
Upvotes: 0
Views: 80
Reputation: 152521
A NullReferenceException
is not thrown when you pass a null parameter, it is thrown when you try and access a member property/method/field on a null reference. In your case it means that this.trainingMethod
is null
.
If trainNetwork
had validation code to verify that the incoming parameters were not null, you would most likely get an ArgumentNullException
with the name of the parameter that was null indicated.
If trainNetwork
tried to reference an instance member on a null value that you passed in, the stack trace would originate from that method, not from train
.
Upvotes: 1
Reputation: 10478
Ensure that this.trainingMethod
is instantiated. From your code it doesn't seem to be.
If it is then you will have to show the full stack trace.
Upvotes: 2