0

これはクラスのコードです:

class Circle extends PApplet {
  //var declarations

  Circle(int duration, int from, int to, PApplet parent, int x, int y, int length, int height){
    this.ani = new Tween(parent, 1.3f, Tween.SECONDS, Shaper.QUADRATIC);
    Class s = Shaper.QUADRATIC;
    this.from = from;
    this.to = to;
    this.len = length;
    this.height = height;
    this.x = x;
    this.y = y;
  }

  void update(){
    int c = lerpColor(this.from, this.to, this.ani.position(), RGB);

    fill(c);
    ellipse(this.x, this.y, this.len, this.height);
  }
}

update()適切にシードされたバージョン(以下の例を参照)で実行するとCircle、次のスタックトレースが取得されます。

Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.core.PApplet.fill(PApplet.java:13540)
at ellipses.Circle.update(Ellipses.java:85)
at ellipses.Ellipses.draw(Ellipses.java:39)
at processing.core.PApplet.handleDraw(PApplet.java:2128)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:190)
at processing.core.PApplet.run(PApplet.java:2006)
at java.lang.Thread.run(Thread.java:662)

内部fill()では、あるべきではないのに何かがnullであることがわかります。最初は、渡された値fill()がどういうわけか間違っていると思います。の値はからfill()来るlerpColor()ので、おそらく私はlerpColor()間違って使用しました。

私のインスタンスはCircle次のようになります。

int c1 = color(45, 210, 240);
int c2 = color(135, 130, 195);

cir = new Circle(1, c1, c2, this, 100, 200, 140, 140);
cir.update();

fill()では、どうすれば/lerpColor正しく使用できますか?

(ところで、私はEclipseでの処理とproclipsingを使用しています。)

4

1 に答える 1

2

まず第一に、あなたのウィンドウの 1 つではないように見えるクラスから PApplet を拡張する必要がある理由が完全にはわかりませんが、脱線します。

あなたが何をしようとしているのか理解できれば、問題は lerpColor ではなく、fill 関数にあります。メインの PApplet の fill 関数を呼び出そうとしていて、この Circle クラスがそうでない場合は、どの PApplet で呼び出すかを指定する必要があります。つまり、すでに送信した親です。私はこのようなことをします。

class Circle extends PApplet {
  //var declarations
  Tween ani;
  int from, to, x, y, len, heightz;

  PApplet parr; // prepare to accept the parent instance

  Circle(int duration, int from, int to, PApplet parent, int x, int y, int length, int height) {
    this.ani = new Tween(parent, 1.3f, Tween.SECONDS, Shaper.QUADRATIC);
    Class s = Shaper.QUADRATIC;
    this.from = from;
    this.to = to;
    this.len = length;
    this.heightz = height;
    this.x = x;
    this.y = y;
    parr = parent; // store the parent instance
  }
  void update() {
    color c = lerpColor(this.from, this.to, this.ani.position(), RGB);
    parr.fill(c); // call fill on the parent
    parr.ellipse(this.x, this.y, this.len, this.height); // this one obviously suffers from the same problem...
  }

これが役立つことを願っています!パック

于 2012-10-22T23:04:02.337 に答える