在人们开始将此问题标记为重复之前,请知道我也花时间查看了类似的问题,并发现其他“错误:课堂上找不到主要方法......”的答案并不明显适用于我的情况(根据我对java的有限理解)
我正在尝试使用文本到语音 api。在我尝试编译之前,Eclipse 不会抱怨以下代码:
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();
}
}
控制台中显示以下错误:
错误:在 com.textToSpeech.FreeTTS 类中找不到主方法,请将主方法定义为:public static void main(String[] args)
上面的代码显然有一个 main 方法,所以有谁知道我为什么会收到这个错误,以及如何修复它?
我认为这与班级名称有关。如果我将类的名称更改为 t2s 之类的名称,然后尝试编译,则会收到此错误:
错误:无法找到或加载主类 com.textToSpeech.t2s
有人有什么想法吗?任何帮助将非常感激。