开发者

Eclipse: How to set the main method for a project?

In Eclipse, when you create a new class, you can select the option "Which methods stubs would like to create:" and you can choose " public static void main(String args[])".

I have created a class with a main method, but I haven't checked that option and I receive this error: "selection does not contain a main type in eclipse". How can I show Eclipse that I have a main method in t开发者_如何学Pythonhe class, without deleting/recreating the class file?

Later Edit: :) My mistake: My main method looks like this: public static void main(String args) and because of this, I received the error message.


I suspect that the signature of your method is wrong. It has to be exactly:

public static void main(String[])

otherwise it won't work. Naming the method Main will fail, omitting the argument to the method will fail. Also, I think the class needs to be public.


Are you sure that you have a method of the type
public static void main(String[] args) ?

You should check if you have no typos in your code. Maybe you could post an example of your main-method's head.


One shortcut that really helps me, Eclipse has syntax suggestions, and if you type "main" into the terminal window and hit control + space, you can choose main method and it'll populate it complete with enclosed braces. Helpful if you're not always quick to remember syntax off the top of your head!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜