Guys tell me, there is a class, there are variables in it:
double[][] weightIH; double[][] weightHO; The default value is null, there is a method where the values of these variables are initialized:
void test() { weightIH = new double[1 + NUM_IN][NUM_HID]; weightHO = new double[1 + NUM_HID][NUM_OUT]; for (int j = 0; j < NUM_HID; j++) for (int i = 0; i < 1 + NUM_IN; i++) weightIH[i][j] = 2.0 * (randomize() - 0.5) * smallwt; for (int k = 0; k < NUM_OUT; k++) for (int j = 0; j < 1 + NUM_HID; j++) weightHO[j][k] = 2.0 * (randomize() - 0.5) * smallwt; } Then, there is a class where the values of these variables are needed:
class Training { void name() { Network network = new Network(); for (int j = 0; j < numHidden; j++) { sumH[j] = network.weightHO[0][j]; for (int i = 0; i < numInput; i++) sumH[j] += input[p][i] * network.weightIH[1 + i][j]; hidden[j] = 1.0 / (1.0 + Math.exp(-sumH[j])); } } } After launch, I catch NullPointerException, i.e. In the Training class, the weightIH and weightOH variables are null.
How to solve the problem with the transfer of variable values, without null?
void test()method, so the variables are not initialized. In general, it is probably better to initialize the values in the constructor. Those. in theNetworkclassNetworkdo a constructor in which to initialize the variables. - I. Smirnovnullis returned - I. SmirnovNetworkobject is created in yourTraining.namemethod. The fact that you are somewhere in themainof some other object has caused something that does not affect it. Perhaps you should change thename()method toname( Network network )and pass the desired object as a parameter. - zRrr