Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java Eclipse error message

  • 28-10-2013 09:35PM
    #1
    Registered Users, Registered Users 2 Posts: 363 ✭✭


    Hi, I'm getting the following error message " Selection does not contain a main type" when I try to run a Java programme through eclipse. Any idea why?

    Background, I'm a part time student starting my second year of Java. I needed to replace my hard drive during the summer and re-install Java, eclipse and the whole environment. This is the first bit of code i've written since then.

    Any code I had done before summer, still runs fine for me. Also, if I right click a class file from last year, and go to 'run as' an option to run as Java application appears. With this problem class file, when I right click, it only gives me an option to 'run configirations'

    If I click the green play button at the top, it gives me the option to run as java application, but it gives the error above. (It also asks, 'Select a way to run 'Year2Java': This is the name of my project, not my class file. Does this matter)

    Thanks for your help. I hope I've been clear enough.


Comments

  • Registered Users, Registered Users 2 Posts: 3,078 ✭✭✭onemorechance


    You are missing:
    public static void main(String args[]) {
    
    }
    

    in your class. The default class must have this main method, this is the first method that gets executed. Start your coding in there.


  • Registered Users, Registered Users 2 Posts: 363 ✭✭silver campaign


    Thanks for that. I'm in work at the moment, but I'll have a look tonight when I get home. Can't believe i'd have left out something so obvious, but you never know, I am a bit rusty all right.


  • Registered Users, Registered Users 2 Posts: 586 ✭✭✭Aswerty


    If you have more than one project in your solution it may be that the wrong project is selected as the startup project.


  • Registered Users, Registered Users 2 Posts: 27,517 ✭✭✭✭GreeBo


    if you are just hitting play then the main class needs to be the current class, you can configure this under the run configuration menu to set a specific main class


Advertisement