"file does not contain class api.configuration" 是什么意思?

What Does "file does not contain class api.configuration" Mean?

请记住,我是 Java 的新手。我不知道 'classes' 和其他东西是什么。

尝试编译(javac -g Sphinx.java)此代码时:

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;    
import java.io.PrintWriter;

import api.Configuration;
import api.SpeechResult;
import api.LiveSpeechRecognizer;

public class Sphinx {
    public static void main(String[] args) throws Exception {

        Configuration configuration = new Configuration();

        configuration.setAcousticModelPath("models/en-us/en-us");
        configuration.setDictionaryPath("models/en-us/cmudict-en-us.dict");
        configuration.setLanguageModelPath("models/en-us/en-us.lm.bin");

        PrintWriter pw = new PrintWriter(new PrintWriter("status.txt"));
        LiveSpeechRecognizer recognizer = new LiveSpeechRecognizer(configuration);
        recognizer.startRecognition(true);
        pw.print("running");
        SpeechResult result = recognizer.getResult();
        recognizer.stopRecognition();
        pw.print("stopped");
        pw.close();

        PrintWriter pw2 = new PrintWriter(new PrintWriter("result.txt"));
        pw2.println(result);
        pw2.close();
    }
}

我收到这个错误:

Sphinx.java:8: error: cannot access Configuration
import api.Configuration;
          ^
  bad source file: .\api\Configuration.java
    file does not contain class api.Configuration
    Please remove or make sure it appears in the correct subdirectory of the sourcepath.

我不太明白 'file does not contain class api.configuration' 是什么意思,或者如何解决它。

查看您的错误消息,您的 ./api/Configuration.java 文件似乎缺少包声明。

你能确定./api/Configuration.java第一行有

package api;

这告诉编译器您的文件可以通过 api 包访问,而不是默认包。