gpt4 book ai didi

java - 错误 : cannot find symbol, 声明了对象,但看不到公共(public)变量

转载 作者:行者123 更新时间:2023-12-02 11:08:02 27 4
gpt4 key购买 nike

我得到了

systemB\Plumber.java:44: error: cannot find symbol
FilterOut.Connect(FilterWildPoints.pipe1);
^
symbol: variable pipe1
location: variable FilterWildPoints of type MiddleFilter
systemB\Plumber.java:56: error: cannot find symbol
FilterWildPoints.pipe1.start();
^
symbol: variable pipe1
location: variable FilterWildPoints of type MiddleFilter
2 errors

即使你,FilterWildPoints 也有一个公共(public)成员变量 pipe1。

重要的想法是,让 Wild Points Filter 将流分成另外两个管道,并将其中一个管道连接到输出。

管道工.java:
package systemB;
public class Plumber
{
public static void main( String argv[])
{
SourceFilter FilterIn = new SourceFilter("./datasets/FlightData.dat");
MiddleFilter FilterTemperature = new MiddleFilterTemperature();
MiddleFilter FilterAltitude = new MiddleFilterAltitude();
MiddleFilter FilterWildPoints = new MiddleFilterWildPoints();
SinkFilter FilterOut = new SinkFilter("./OutputB.dat");

FilterOut.Connect(FilterWildPoints.pipe1);
FilterWildPoints.Connect(FilterAltitude);
FilterAltitude.Connect(FilterTemperature);
FilterTemperature.Connect(FilterIn);

FilterIn.start();
FilterTemperature.start();
FilterAltitude.start();
FilterWildPoints.pipe1.start();
FilterOut.start();
} // main
} // Plumber

MiddleFilterWildPoints.java:
package systemB;
import java.nio.ByteBuffer;

public class MiddleFilterWildPoints extends MiddleFilter
{
public MiddleFilter pipe1;
public MiddleFilter pipe2;

MiddleFilterWildPoints()
{
this.pipe1 = new MiddleFilter();
this.pipe2 = new MiddleFilter();
}
//...

} // MiddleFilter

我对java不是很熟悉,需要这个来分配,但我找不到错误。

最佳答案

您已声明 FilterWildPointsMiddleFilter ,它没有 pipe1 field 。

相反,声明 FilterWildPoints类型为 MiddleFilterWildPoints :

MiddleFilterWildPoints FilterWildPoints = new MiddleFilterWildPoints();

java 编译器只查看声明的类型。

最好遵循以小写字母开头的变量名称的标准 java 命名约定。 IE
MiddleFilterWildPoints filterWildPoints = new MiddleFilterWildPoints();

这样类名和变量名更容易区分。

关于java - 错误 : cannot find symbol, 声明了对象,但看不到公共(public)变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51227540/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com