java - 错误:即使它是公共变量也找不到符号?
问题描述
我遇到了很多错误,例如下面的错误,我很困惑为什么我确保不直接访问所述私有变量
symbol: method GetP()
location: class LineSegment
FastCollinearPoints.java:47: error: cannot find symbol
Point big = nonFinishedSegments.get(i).GetQ()
这是声明未找到符号的相关类
public class LineSegment {
private Point p; // one endpoint of this line segment
private Point q; // the other endpoint of this line segment
public Point GetQ(){
return this.q;
}
public Point GetP(){
return this.p;
}
public LineSegment(Point p, Point q) {
if (p == null || q == null) {
throw new NullPointerException("argument is null");
}
this.p = p;
this.q = q;
}
这是发现错误的其他脚本的一部分(所有 GetQ 和 GetP 都会出现错误)
public FastCollinearPoints(Point[] points) {
final ArrayList<LineSegment> nonFinishedSegments = new ArrayList<LineSegment>();
if (checkForNullPoints(points) || checkForDuplicates(points)) {
throw new IllegalArgumentException("exception");
}
Point[] copy = points.clone();
Arrays.sort(copy);
for(int i = 0; i < copy.length-1; i++){
nonFinishedSegments.add( new LineSegment(copy[i],copy[i+1]));
}
for(int i = 0; i < nonFinishedSegments.size(); i ++){
final ArrayList<LineSegment> sameAngle = new ArrayList<>();
Point small = nonFinishedSegments.get(i).GetP();
Point big = nonFinishedSegments.get(i).GetQ();
int size = 2;
double angle = nonFinishedSegments.get(i).GetP().slopeTo(nonFinishedSegments.get(i).GetQ());
for (LineSegment nonFinishedSegment : nonFinishedSegments) {
if (nonFinishedSegment.GetP().slopeTo(nonFinishedSegment.GetQ()) == angle) {
sameAngle.add(nonFinishedSegment);
}
}
for (LineSegment lineSegment : sameAngle) {
if (lineSegment.GetP() == big) {
big = lineSegment.GetQ();
size++;
size++;
}
解决方案
推荐阅读
- arduino - 通过按下按钮打开和关闭机器人手的 arduino 代码出现问题
- android - WearOS Ticwatch 幻影 AGC
- mysql - MySQL 对列名区分大小写
- python - 尝试安装 python 3 模块时权限被拒绝
- sparql - 维基数据查询服务中的命名子查询慢
- pandas - 如何根据条件将月数据转换为 nan?
- mysql - 使用 Flutter 连接数据库时出现问题
- windows - host=$decideOnStartup 在 Windows EC2 上的 splunk 配置中不起作用
- entity-framework - 如果存在子视图,如何使用产品实体
- reactjs - React Admin dataProvider 在创建期间未发送 id