简体   繁体   English

Java无法解析或不是字段

[英]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. 我正在研究在神经网络中编写一个for循环,它为循环条件本身的一部分抛出了错误。

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: NeuronLayers本身是一个ArrayList,定义如下:

// 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: numNeurons是另一个类SNeuronLayer的整数值,其定义如下:

// 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". 并显示“ numNeurons无法解析或不是字段”。

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. 任何帮助将不胜感激,因为我将不得不在for循环本身中引用来自同一第二类的另一个ArrayList,并且我想知道如何最好地用短语表述以确保我的代码正常工作。

Hint: When you do neuronLayers.get(i) , it returns double, so you can not access the SNeuronLayer . 提示:执行neuronLayers.get(i) ,它返回double,因此您无法访问SNeuronLayer Instead, Try to make ArrayList of that class and include that double value as one of the attributes. 而是尝试使该类的ArrayList并将该double值包括为属性之一。 So you can access both Double and SNeuronLayer . 因此,您可以访问DoubleSNeuronLayer

Let's assume you have class named SNeuronLayer . 假设您有一个名为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: 您可以像这样访问Int值:

list.get(i).numNeurons;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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