'Cannot find symbol - variable args' 尝试启动新 class 时出错

'Cannot find symbol - variable args' error when attempting to launch new class

我在将 'jump' 编码到另一个 class 时遇到错误。我创建了一个 GUI,并添加了一个 ActionListener。我希望程序在单击 'button2' 时转到另一个 class(称为 'Project2')。但是,当为此输入代码 'Project2.main(args);' 时,出现错误 'Cannot find symbol - variable args' .

提前致谢!

根据@Mike Nakis 的评论,您没有要传递给函数 main() 的变量 args,因此创建空字符串数组 args 并传递给 main 函数。如果需要,您可以将参数字符串添加到数组中。因此,将代码更改为:

String[] args = {};//new line 
Project2.main(args);

See related SO POST