接收NullPointerException

时间:2019-05-30 20:55:38

标签: java processing

请注意,我已经阅读了What is a NullPointerException and how do I fix it?指南。

错误指向的代码行不存在,并且我看不到任何东西会导致某些东西调用没有值的东西。

两个Java文件

//ParticleSystems

Particle[] ps;

int pAmount = 10;


void setup() {
  size(800, 600);
  for (int x = 0; x < pAmount; x++) {
    ps[x] = new Particle();
  }
}

void draw() {
  background(51);
  for (int x = 0; x < ps.length; x++) {
    ps[x].show();
    ps[x].update();
  }
}


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


  Particle() {
    location = new PVector(width/2, 25);
    acceleration = new PVector(0, 0.05);
    velocity = new PVector(random(-1, 1), random(-1, 1));
    lifespan = 255;
    radius = 10;
  }

  void update() {
    velocity.add(acceleration);
    location.add(velocity);
    if (location.y > radius + height) {
      lifespan = 255;
      location.x = width/2;
      location.y = 25;
      velocity.y = .05;
    }
    lifespan -= 1;
  }

  void show() {
    noStroke();
    fill(255, lifespan);
    ellipse(location.x, location.y, radius*2, radius*2);
  }
}

错误

java.lang.ClassCastException: processing.app.RunnerListenerEdtAdapter cannot be cast to processing.mode.java.JavaEditor
    at processing.mode.java.JavaMode.handleTweak(JavaMode.java:145)
    at processing.mode.java.JavaEditor.lambda$0(JavaEditor.java:1101)
    at java.lang.Thread.run(Thread.java:748)

0 个答案:

没有答案