-1

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.

greg-449
  • 109,219
  • 232
  • 102
  • 145
Patrick
  • 87
  • 1
  • 7
  • I don't see anything wrong in the definition for main method. Is the project compiling OK in Eclipse? Try with the command "Project -> Build All" and check in the Problems view to see if there are any compile issues. – eugenioy Jun 19 '15 at 14:51
  • Is the name of the source .java file the same as the class name? Is the source in the correct folder (probably `src/com/textToSpeech`)? Is eclipse looking in the correct source folder (happens with maven builds, when sources are in src/main/java and eclipse fails to understand this)? – dhke Jun 19 '15 at 15:24
  • You should also try doing a Project -> Clean, followed by Project -> Build All – T.D. Smith Jun 19 '15 at 15:27
  • **"Eclipse isn't complaining about the following code until I try to compile"**? or -Eclipse isn't complaining about the following code until I try to **run**. Which one? – Bacteria Jun 19 '15 at 17:34

1 Answers1

-1

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.

nom
  • 256
  • 3
  • 16