简体   繁体   中英

Java Cannot be resolved or is not a field

Writing a for loop in a neural network i'm working on, and it's throwing an error for part of the loop condition itself.

The code is as follows:

// for each neuron sum the (inputs * corresponding weights) .Throw
// the total at our sigmoid function to get the output.

for (int j = 0; j < neuronLayers.get(i).numNeurons; ++j)
    {}
}

neuronLayers itself is an ArrayList, defined as such:

// storage for each layer of neurons including the output layer

private ArrayList<Double> neuronLayers;

and numNeurons is an integer value from another class, SNeuronLayer, defined as such:

// the number of neurons in this layer

int numNeurons;

The error is with

neuronLayers.get(i).numNeurons;

and it says "numNeurons cannot be resolved or is not a field".

Any help would be greatly appreciated, as i'm going to have to reference another ArrayList from the same second class in the for loop itself and i'd like to know how best to phrase it to ensure my code works.

Hint: When you do neuronLayers.get(i) , it returns double, so you can not access the SNeuronLayer . Instead, Try to make ArrayList of that class and include that double value as one of the attributes. So you can access both Double and SNeuronLayer .

Let's assume you have class named SNeuronLayer . Than keep following attributes in it.

class SNeuronLayer{
    int numNeurons;
    double your_double;
}

now define array list as:

ArrayList<SNeuronLayer> list;

So you can access double value by

list.get(i).your_double;

and you can access Int value like:

list.get(i).numNeurons;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM