如何解决线程中的异常"动画线程"显示java.lang.NullPointerException?

时间:2014-01-19 16:30:25

标签: java processing

在解决了我之前的错误之后,这里出现了另一个NPE代码:

public void displayCircles() {
    for (Circle menu : circles) {
        if (menu.getX() < defaultCircles[pulseCircle].getX() + 0.5 && 
            menu.getX() > defaultCircles[pulseCircle].getX() - 0.5 && 
            menu.getY() < defaultCircles[pulseCircle].getY() + 0.5 && 
            menu.getY() > defaultCircles[pulseCircle].getY() - 0.5) 
            {
                choiceCircle = menu;
                pulsingEffect(menu);
            }

上述代码的第三行给了我NPE。有什么想法吗?

defaultCircles:

Circle[] defaultCircles = new Circle[circles.length];

void polygon(int n, float cx, float cy, float r) {
    float angle = 210.0f / n;
    for (int i = 0; i < n; i++) {
        circles[i] = new Circle(i + 1, cx + r * cos(radians(angle * i)), cy + r * sin(radians(angle * i)));
        defaultCircles[i] = new Circle(i + 1, cx + r * cos(radians(angle * i)), cy + r * sin(radians(angle * i)));
    }
}

pulseCircle:

void findPulseCircle() {
    float max = circles[0].getY();
    for (int i = 0; i < circles.length; i++) {
        if (circles[i].getY() > max) {
            max = circles[i].getY();
            pulseCircle = i;
        }
    }
}

0 个答案:

没有答案