有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java当我尝试向ArrayList中添加一个新点时出错

尝试将新点添加到ArrayList时出错 这是我的编码器,我不明白为什么会有错误

这是我的重点课程

public class Point {

public int X;
public int Y;

public Point(int X, int Y) {
    this.X = X;
    this.Y = Y;

}

public int getX() {
    return X;
}

public void setX(int x) {
    X = X;
}

public int getY() {
    return Y;
}

public void setY(int y) {
    Y = y;
}


// Field-Area to be Colored
public Point Color_Field(Point a) {

    Point fieldAreaColor= new Point(0, 0);

    fieldAreaColor.setX(a.getX() + 5);
    fieldAreaColor.setX(a.getY() + 5);

    return fieldAreaColor;
}

}

这是我的列表类,我尝试在列表中添加新的点 列表这是行不通的

package Handler;

import java.awt.List;
import java.util.ArrayList;

import Basic_Geom.Point;
public class Liste {


    ArrayList<Point> points=new ArrayList<Point>();

    points.add(new Point(2,3)); //here is my error i can t add a point to my list.


}

共 (1) 个答案

  1. # 1 楼答案

    points.add(new Point(2,3));这样的语句必须在某个方法/构造函数中