0

im trying to run a Sphinx's HelloWOrd program, it needs a .jar file to work.

im trying to add a jar file in the classpath, but im getting some errors

contend.util does not exist import edu.cmu.sphinx.frontend.util.Microphone; ^ home/karen/workspace/hola/src/hola/HelloWorld.java:4: package edu.cmu.sphinx.recognizer does not exist import edu.cmu.sphinx.recognizer.Recognizer; ^ home/karen/workspace/hola/src/hola/HelloWorld.java:5: package edu.cmu.sphinx.result does not exist import edu.cmu.sphinx.result.Result; ^ home/karen/workspace/hola/src/hola/HelloWorld.java:6: package edu.cmu.sphinx.util.props does not exist import edu.cmu.sphinx.util.props.ConfigurationManager; ^ home/karen/workspace/hola/src/hola/HelloWorld.java:11: cannot find symbol symbol : class ConfigurationManager location: class hola.HelloWorld ConfigurationManager cm; ^ home/karen/workspace/hola/src/hola/HelloWorld.java:14: cannot find symbol symbol : class ConfigurationManager location: class hola.HelloWorld cm = new ConfigurationManager(args[0]); ^ home/karen/workspace/hola/src/hola/HelloWorld.java:16: cannot find symbol symbol : class ConfigurationManager location: class hola.HelloWorld cm = new ConfigurationManager(HelloWorld.class.getResource("helloworld.config.xml")); ^ home/karen/workspace/hola/src/hola/HelloWorld.java:19: cannot find symbol symbol : class Recognizer location: class hola.HelloWorld Recognizer recognizer = (Recognizer) cm.lookup("recognizer"); ^ home/karen/workspace/hola/src/hola/HelloWorld.java:19: cannot find symbol symbol : class Recognizer location: class hola.HelloWorld Recognizer recognizer = (Recognizer) cm.lookup("recognizer"); ^ home/karen/workspace/hola/src/hola/HelloWorld.java:23: cannot find symbol symbol : class Microphone location: class hola.HelloWorld Microphone microphone = (Microphone) cm.lookup("microphone"); ^ home/karen/workspace/hola/src/hola/HelloWorld.java:23: cannot find symbol symbol : class Microphone location: class hola.HelloWorld Microphone microphone = (Microphone) cm.lookup("microphone"); ^ home/karen/workspace/hola/src/hola/HelloWorld.java:36: cannot find symbol symbol : class Result location: class hola.HelloWorld Result result = recognizer.recognize(); ^ 12 errors

my question is: I have to add all the packages that needs my project or only the jar file and the main class?

Sugest please!

This is the HelloWord Program:

package hola;

import edu.cmu.sphinx.frontend.util.Microphone;
import edu.cmu.sphinx.recognizer.Recognizer;
import edu.cmu.sphinx.result.Result;
import edu.cmu.sphinx.util.props.ConfigurationManager;

public class HelloWorld {
    public static void main(String [] args){
        System.out.println("VIcente y karen");
        ConfigurationManager cm;
        System.out.println("Karen entiende esto");
                if (args.length > 0) {
                    cm = new ConfigurationManager(args[0]);
                } else {
                    cm = new ConfigurationManager(HelloWorld.class.getResource("helloworld.config.xml"));
                }

                Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
                recognizer.allocate();

                // start the microphone or exit if the programm if this is not possible
                Microphone microphone = (Microphone) cm.lookup("microphone");
                if (!microphone.startRecording()) {
                    System.out.println("Cannot start microphone.");
                    recognizer.deallocate();
                    System.exit(1);
                }

                System.out.println("Say: (Good morning | Hello) ( Bhiksha | Evandro | Paul | Philip | Rita | Will )");

                // loop the recognition until the programm exits.
                while (true) {
                    System.out.println("Start speaking. Press Ctrl-C to quit.\n");

                    Result result = recognizer.recognize();

                    if (result != null) {
                        String resultText = result.getBestFinalResultNoFiller();
                        System.out.println("You said: " + resultText + '\n');
                    } else {
                        System.out.println("I can't hear what you said.\n");
                    }
                }
    }

}

barryhunter
  • 20,886
  • 3
  • 30
  • 43
karensantana
  • 1,599
  • 4
  • 21
  • 34
  • All jars needed by your program has to be added to the classpath. – smk Nov 11 '12 at 00:49
  • i only have 1 jar file but my project depends on some packages. I have to add these packages? – karensantana Nov 11 '12 at 00:51
  • It would be better if you paste the Hello World program for us to understand whether you are coding it correctly. – jbx Nov 11 '12 at 00:52
  • Are you using an IDE? If yes which one, and how did you 'add' your jar file to the classpath? – jbx Nov 11 '12 at 01:02
  • Yes im using Eclipse IDE and am adding with following command: – karensantana Nov 11 '12 at 01:04
  • javac -classpath home/karen/HelloWorld.jar home/karen/workspace/hola/src/hola/HelloWorld.java – karensantana Nov 11 '12 at 01:06
  • Follow the instructions on the link I gave you below in my answer. Eclipse will take care of that automatically when you compile or run the program. – jbx Nov 11 '12 at 01:08

1 Answers1

0

Most probably you did not import the right classes or packages in your program (are the package names correct? Seems like the compiler is not recognising them from the first few error lines).

Even though you have the JAR file with the classes in your classpath, you still have to import them in your specific class for the compiler to know which external classes you need.

You also have to do it for the inbuilt Java classes (java.util.ArrayList for example). If you provide your program we would be able to help you better.

If the Jar file you have also depends on other libraries, then they have to be provided too.

Open your JAR file with a zip program (such as winrar) and check if the packages you are importing exist. You should see a folder named edu, inside it further folders cmu/sphinx/frontend/util and then inside it Microphone.class. Similarly for edu.cmu.sphinx.recognizer with a file Recognizer.class.

If you are using an IDE (such as Eclipse, Netbeans or IntelliJ IDEA) make sure you are adding the jar file to the list of project libraries.

For Eclipse, you have to follow the procedure here

jbx
  • 21,365
  • 18
  • 90
  • 144
  • but does Helloworld.jar actually have those classes in it? So if you open it with winrar or similar, do you find the folders edu/cmu/sphinx etc.? – jbx Nov 11 '12 at 01:11
  • So you are sure you added Helloworld.jar to the build path, and is Eclipse complaining that those packages do not exist? I.e. is it displaying a red line underneath those import lines? If yes what happens when you just press the 'Play' button and run the program from Eclipse? – jbx Nov 11 '12 at 01:44
  • Here is my output: Exception in thread "main" java.lang.NullPointerException at edu.cmu.sphinx.util.props.SaxLoader.load(SaxLoader.java:74) at edu.cmu.sphinx.util.props.ConfigurationManager.(ConfigurationManager.java:58) at hola.HelloWorld.main(HelloWorld.java:16) – karensantana Nov 11 '12 at 02:00
  • Now this is a totally different error. I don't know what you have at Line 16 of your HelloWorld.java but most probably its related to the parameter you're passing to the constructor of ConfigurationManager. So most probably "helloworld.config.xml" does not really exist? – jbx Nov 11 '12 at 02:06
  • So the path is incorrect most probably. If it is at the root of the jar file I think it needs to be: "/helloworld.config.xml" – jbx Nov 11 '12 at 02:15