简体   繁体   中英

Error: Main method not found in class... why am I getting this?

Before people start flagging this question as a duplicate, know that I took the time too look at similar questions, and found that the answers to other "Error: Main method not found in class..." were not clearly applicable to my situation (according to my limited understanding of java)

I'm trying to utilize a text to speech api. Eclipse isn't complaining about the following code until I try to compile:

package com.textToSpeech;

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;

public class FreeTTS {

    private static final String VOICENAME_kevin = "kevin";
     private String text; // string to speech

     public FreeTTS(String text) {
      this.text = text;
     }

     public void speak() {
      Voice voice;
      VoiceManager voiceManager = VoiceManager.getInstance();
      voice = voiceManager.getVoice(VOICENAME_kevin);
      voice.allocate();
      voice.speak(text);
     }

     public static void main(String[] args) {
      String text = "FreeTTS was written by the Sun Microsystems Laboratories "
        + "Speech Team and is based on CMU's Flite engine.";
      FreeTTS freeTTS = new FreeTTS(text);
      freeTTS.speak();
     }



}

The following error shows up in the console:

Error: Main method not found in class com.textToSpeech.FreeTTS, please define the main method as: public static void main(String[] args)

The code above obviously has a main method, so does anyone know why I am getting this error, and furthermore how I can fix it?

I think it has something to do with the name of the class. If I change the name of the class to something like t2s and then try to compile, I get this error:

Error: Could not find or load main class com.textToSpeech.t2s

Anybody have any thoughts? Any help would be really appreciated.

You may have messed up your project properties. I don't use eclipse, so I cannot say for sure, but try creating a new project and adding the same code to it without fiddling with the properties . The class name and the file name should be the same, check that. Also make sure that the source file is in the same package folder. If nothing works, just create a new project.

Cheers.

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