Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Eclipse error message

Options
  • 28-10-2013 9:35pm
    #1
    Registered Users 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 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 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 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 Posts: 27,134 ✭✭✭✭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