未定义构造函数[正在处理]

Constructor not defined [Processing]

我正在做一个关于 ArrayList/Particle 系统的非常基础的教程。我一直收到 "constructor is undefined error",但我不明白为什么。谷歌搜索带来了很多更复杂的 question/answers。我错过了什么?这在去年有变化吗?

ArrayList<Particle> plist;

void setup(){
    size(640, 360);
    plist = new ArrayList<Particle>();
    println(plist);
    plist.add(new Particle());
}

void draw(){
    background(255);


}


class Particle {
  PVector location;
  PVector velocity;
  PVector acceleration;
  float lifespan;

  Particle(PVector l){
    // For demonstration purposes we assign the Particle an initial velocity and constant acceleration.
    acceleration = new PVector(0,0.05);
    velocity = new PVector(random(-1,1),random(-2,0));
    location = l.get();
    lifespan = 255;
  }

  void run(){
    update();
    display();
  }

  void update(){
    velocity.add(acceleration);
    location.add(velocity);
    lifespan -= 2.0;
  }

  void display(){
    stroke(0, lifespan);
    fill(175, lifespan);
    ellipse(location.x, location.y,8,8);
  }

  boolean isDead(){
    if(lifespan < 0.0){
      return true;
    }else{
      return false;
    }
  }
}

这是您的 Particle 构造函数:

Particle(PVector l){

请注意它需要一个 PVector 参数。

这就是您调用 Particle 构造函数的方式:

plist.add(new Particle());

这一行有一个错误:the constructorParticle()does not exist. 而这正是您的问题所在。构造函数 Particle() 不存在。仅 Particle(PVector) 存在。

换句话说,请注意您没有给它一个 PVector 参数。这就是你的错误告诉你的。

要解决此问题,您需要提供一个 PVector 参数,或者您需要更改构造函数以使其不再需要一个。