Search code examples
javaidedrjava

What does "Illegal Class Literal" mean?


Just started using DrJava, and I'm getting an Illegal Class Literal error when I try to run my code. My code compiles, and no issue arises until runtime. Even just the following leads to the error when I run 'java Percolation(5)' in the interaction terminal.

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

I couldn't find anything on Google; any ideas what could be going on here? I feel like I'm missing something stupid. Thanks!


Solution

  • To run your program, you have to call a starting or main method. This method as to be public static void and it has to take VarArgs or an Array for your arguments:

    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]));
    }
    

    Then you can call your program via

    java Percolation 5