When I create a new main.java file in the default package in my Eclipse project, it generates a main method that looks like this:
public static void main(String[] args) { }
This immediately raises a warning saying This method has a constructor name . A suggested fix is ββto remove void :
public static main(String[] args) { }
Now, and not a warning, I get an error message: Illegal modifier for the constructor in type main; only public, protected & private are permitted Illegal modifier for the constructor in type main; only public, protected & private are permitted . If I remove static , my code now looks like this:
public main(String[] args) { }
This time I still get an error message, but something else:
Error: Main method not found in class main, please define the main method as: public static void main(String[] args)
Argggh! But that brings me back to where I started. How to define the main method so that I don't get any errors or warnings?
I am using Eclipse Juno Service Release 2 and JavaSE-1.7. Please note: I am very new to Java; I come from C # background. Also, this is probably a recurring question, but I cannot find it.
source share