umesh umesh - 3 months ago 13
Java Question

i am trying to do following in eclipse:

i am trying to do following in eclipse:

package javav;
public class Regex {
public static void main (String[] s)
{
System.out.println("java");
}
}


i am getting following error

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

Answer

looks like you've declared a String class among your own classes. To prove this:

class String {
}

public class Regex {
    public static void main(String[] args) {
        System.out.println("won't get printed");
    }
    public static void main(java.lang.String[] args) {
        System.out.println("worked");
    }
}

If you execute this code, it will print "worked" in the console. If you comment the second main method, the application will throw an error with this message (similar for your environment):

Error: Main method not found in class xxx.xxxx.xx.regex, please define the main method as:

public static void main(String[] args)