什么" Illegal Class Literal"意思?

时间:2014-10-02 07:10:24

标签: java ide drjava

刚开始使用DrJava,当我尝试运行我的代码时,我收到了一个Illegal Class Literal错误。我的代码编译,直到运行时才出现问题。当我运行java渗透(5)'时,即使只是以下内容也会导致错误。在交互终端。

public class Percolation {
    public Percolation(int N)  {
        System.out.println(N);
    }    
}

我无法在Google上找到任何内容;任何想法可能会在这里发生什么?我觉得我错过了一些愚蠢的东西。谢谢!

2 个答案:

答案 0 :(得分:1)

您的班级需要main方法才能运行它。 http://docs.oracle.com/javase/tutorial/getStarted/application/

然后,如果要将参数传递给main方法,可以通过

调用它
java Percolation 5

java Percolation(5)

答案 1 :(得分:1)

要运行程序,您必须调用start或main方法。此方法为public static void,并且必须为参数采用VarArgs或数组:

public static void main (String[] args) {
    // in here, you can do stuff like calling other functions, or creating objects

    // no checks, just demo how to use the args:
    Perlocation p = new Perlocation(Integer.parseInt(args[0]));
}

然后你可以通过

打电话给你的程序
java Percolation 5
相关问题