正在处理 - "unexpected token: void"

Processing - "unexpected token: void"

我正在使用下面的代码来模拟 "Purple Rain"(来自 The Coding Train on YouTube)。

Class Drop(){
  float x = width/2;
  float y = 0;
  float yspeed = 1;

  void fall(){
    y = y + yspeed;
  }
  void show(){
    stroke(138, 43, 226);  //purple rain
    line(x, y, x, y+10);
  }

}

但是,我在第 6 行收到错误 unexpected token: void

void fall(){     

我看不到任何语法错误 - 有人可以告诉我为什么会出现此错误吗?

您确实有语法错误。 Class 关键字应该是 class 小写 c。 class 名称后也不应该有括号。

另请参阅我的回答。 Processing 编辑器不喜欢只有 class 定义而没有像 setup()draw().

这样的 Processing 函数

旁注:您可能想尝试以 "what syntax error am I not seeing?" 的心态来解决这样的问题,而不是说 "I have no syntax errors" - 编译器不会说谎,所以说您没有语法错误就会消失有点冒昧。