-1

This is my code:

import java.util.SortedSet;
import java.util.TreeSet;
public class Example9 {
    public static void main(String[] args) {
        SortedSet<String> s = new TreeSet<String>();
        s.add("Practice");
        s.add("Stack Overflow");
        System.out.print(s);    
    }
}

I am getting the following error when I execute this program:

Error: Main method not found in class Example9, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application

Can anyone please help me?

kalehmann
  • 4,821
  • 6
  • 26
  • 36
  • how did you execute this class? – Lasitha Benaragama Sep 03 '18 at 13:56
  • 3
    I suggest you clean the project completly (Something like "Project > Clean...") See the duplicate to understand why this could solve your case. – AxelH Sep 03 '18 at 13:57
  • Possible duplicate of [Function of Project > Clean in Eclipse](https://stackoverflow.com/questions/4549161/function-of-project-clean-in-eclipse) – AxelH Sep 03 '18 at 13:58
  • After I have cleaned my project my code is working fine. Now the thing is that after doing so each time I change the code it is giving me the same old output. – Sachin Koparde Sep 04 '18 at 14:32

3 Answers3

1

Is it possible that your entry point is not set correctly?

Right click your project > 'Run configuration' 

From here, you should be able to set which class has its main method run when you click Run.

AxelH
  • 14,325
  • 2
  • 25
  • 55
TheMri
  • 1,217
  • 8
  • 12
  • I doubt it since the error mention the correct class name but that's a start. – AxelH Sep 03 '18 at 14:03
  • This is not an answer, should be a comment. If you don't have enough rep to comment, please try answering a different question until you do. – AmmoPT Sep 03 '18 at 14:09
  • You should complete the "_you should be able to set which class_" part with at least the name of the parameter or even better with a screenshot of the popup dialog. For the rest, that's not bad for a first one ! – AxelH Sep 03 '18 at 14:17
0

Your code seems to be running fine.

I just ran it and it seems ok.

Could you try making a new eclipse project, and clicking run on the new class?

enter image description here

Menelaos
  • 23,508
  • 18
  • 90
  • 155
  • Why do you need to create a new project ? This would be time consuming for bigger project to create a new one each time eclipse decide to stop working (because it happen sometimes). They are simpler ways to solve this. – AxelH Sep 03 '18 at 14:05
  • @AxelH obviously not for a big project. But in a big project the developer would know how to run the application and configure the project. This is clearly a configuration issue. For HIS specific project, it's much easier to just copy/paste and do it again. – Menelaos Sep 03 '18 at 14:07
0

one probability is you might have created JavaFX application not the Java application. in eclipse.

I check your code it is worked fine. here are steps to create java Application

  1. Create Java Project Select from the menu File --> New --> Java Project.

Enter "HelloWorld" as the project name. Keep rest of the settings as it is as shown in the following screenshot.

  1. Create Java Class Right click on 'com.vipul.example' package and select from context menu New --> Class.

Write "HelloWorld" in the 'Name' field and select the check-box for 'public static void main(String[] args)'.

Click "Finish" button. Eclipse will generate a java class and open the same in the java editor as shown below.

  1. Run Your Code Right click on 'HelloWorld.java' and select from context menu 'Run As' --> 'Java Application'.

  2. Console Output Your code will print 'Hello World' in the eclipse console.

Here is full demo of java project in eclipse example

Vipul Gulhane
  • 761
  • 11
  • 16