我試圖將this []傳遞給類並使用它來定義兩個rects的寬度和高度。這只是我初始代碼的簡化版本,而我得到令牌 「]」 的errorsyntax錯誤,此令牌」後VariableDeclaratorld預期,這裏是我的代碼:?令牌上的語法錯誤「]」,VariableDeclaratorld預期在此令牌之後
ArrayList textlines;
int xpos=20;
int ypos=20;
int[]thistime = new int[2];
void setup() {
size(1200, 768);
textlines = new ArrayList();
thistime[0] =3;
thistime[1] =30;
}
void draw() {
}
void mousePressed() {
textlines.add(new Line(xpos, ypos,thistime));
for (int i=0; i<textlines.size(); i++) {
Line p=(Line)textlines.get(i);
p.display();
}
}
class Line {
int x;
int y;
int thatimee[];
Line(int xpo, int ypo, int thetimee[]) {
x =xpo;
y =ypo;
thatimee[]= new int[thetimee.length];
thatimee[0]=thetimee[0];
thatimee[1]=thetimee[1];
}
void display() {
fill(50, 50, 50);
rect(random(width), random(height), thatimee[0],thatimee[0]);
rect(random(width), random(height), thatimee[1], thatimee[1]);
}
}
的錯誤是在該行
thatimee[]= new int[thetimee.length];
誰知道原因