且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

类“星云”不存在

更新时间:2021-10-16 02:50:44

基本上,Processing编辑器可以处理两种类型的代码。第一种是函数调用的基本列表,例如:

Basically, the Processing editor can handle two types of code. The first type is a basic list of function calls, like this:

size(500, 200);
background(0);
fill(255, 0, 0);
ellipse(width/2, height/2, width, height);

使用这种类型的代码,Processing一次只运行一个命令。

With this type of code, Processing simply runs the commands one at a time.

第二种代码是带有函数定义的真实程序,如下所示:

The second type of code is a "real" program with function definitions, like this:

void setup(){
   size(500, 200);
}

void draw(){
    background(0);
    fill(255, 0, 0);
    ellipse(width/2, height/2, width, height);
}

使用这种类型的代码,Processing调用设置()函数开始,然后每秒调用 draw()函数60次。

With this type of code, Processing calls the setup() function once at the beginning, and then calls the draw() function 60 times per second.

但是请注意,您不能具有混合使用两种类型的代码:

But note that you can't have code that mixes the two types:

size(500, 200);

void draw(){
    background(0);
    fill(255, 0, 0);
    ellipse(width/2, height/2, width, height);
}

这会给您一个编译器错误,因为 size()函数不在函数内部!

This will give you a compiler error, because the size() function is not inside a function!

您的代码发生了什么变化,正在处理中,您发现尚未定义任何草图-级别的函数,因此它尝试将其视为第一类代码。但是随后它看到了类定义,它们仅在第二种类型的代码中有效。这就是为什么您遇到错误。

What's going on with your code is Processing sees that you haven't defined any sketch-level functions, so it tries to treat it as the first type of code. But then it sees class definitions, which are only valid in the second type of code. That's why you're getting an error.

要解决您的问题,只需定义 setup()和/或代码中的 draw()函数,因此Processing知道它是一个真实程序。

To fix your problem, just define a setup() and/or draw() function in your code, so Processing knows it's a "real" program.