首页 > 解决方案 > 错误:即使它是公共变量也找不到符号?

问题描述

我遇到了很多错误,例如下面的错误,我很困惑为什么我确保不直接访问所述私有变量

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++;

                }

标签: java

解决方案


推荐阅读