我想创建一个图形,其中为ArrayList
. 预期的最终结果是水平方向上的一系列矩形,用于ArrayList
.
我尝试了以下代码,但NullPointerException
在执行代码时出现错误。谁能告诉我如何获得我期望的输出?
import processing.core.*;
public class Processing extends PApplet {
ArrayList<Integer> test = new ArrayList<Integer>();
private PApplet parent;
int x = 100;
int y = 100;
public void setup() {
size(640, 600);
background(255);
test.add(10);
test.add(20);
test.add(30);
noLoop();
}
public void draw() {
for(int testing: test){
printTask(x,y);
}
}
public void printTask(int x, int y){
parent.rect(10,10,x,y);
}
static public void main(String args[]) {
PApplet.main(new String[] { "--bgcolor=#ECE9D8", "Processing" });
}
}
异常的堆栈跟踪:
Exception in thread "Animation Thread" java.lang.NullPointerException
at Processing.printTask(Processing.java:30)
at Processing.draw(Processing.java:25)
at processing.core.PApplet.handleDraw(PApplet.java:1602)
at processing.core.PApplet.run(PApplet.java:1503)
at java.lang.Thread.run(Unknown Source)