这是一个类的代码:
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()
,不应该的东西是空的。我首先会假设传递给的值在fill()
某种程度上是错误的。to 的值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 的处理。)