简体   繁体   中英

Eclipse not recognizing my “Main” method

I'm trying to write a "Hello, World" variant program in Eclipse, and I can't seem to be able to run my program.

Here's the code:

/**
 * 
 */
package GreeterPackage;

/**
 * @author Raven Dreamer
 * Prints out "Hello, World" in three languages:
 * English, French, and Spanish.
 */
public class GreeterProg {

    /** 
     * returns "Hello, World" three times, once
     * in English, once in French, and once in 
     * Spanish.
     */
    public static void Main(String[] args){
    /** instances of the three greeter
     * classes so the non-static methods
     * can be called.
     */
    EnglishGreeter eng = new EnglishGreeter();
    FrenchGreeter fre = new FrenchGreeter();
    SpanishGreeter spa = new SpanishGreeter();
    System.out.println(eng.greet());
    System.out.println(fre.greet());
    System.out.println(spa.greet());

}
}

And here's my code for SpanishGreeter (French and English greeter are identical, currently)

/**
 * 
 */
package GreeterPackage;

    /**
     * @author Raven Dreamer
     * Returns "Hello, World!" but in Spanish!
     */
    public class SpanishGreeter extends greeter {

        /**Spanish string of "Hello, World!"
         */
        private String GREET = "¡Hola, World!";

        /** 
         * returns "Hello, World" in Spanish
         */
        public String greet() {
            return GREET;
        }

    }

The code compiles fine with no errors, but when I try to run the program as a java application, I get the following error: 在此输入图像描述

So I am left baffled as to what, exactly, the problem is. Am I missing something salient in terms of how I set the project up in the first place?

The problem is that you have Main with a capital letter. Java is case-sensitive.

The full method signature is: public static void main(String [] args)

你的主要方法需要是一个小写的“主”。

"main" must be in lowercase only. Java method names are case-sensitive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM