title: java.lang.NullPointerException for JSAPI Speech Recognizer in Java
body: <p>While I tried the simple Speech Recognizer JSAPI (JSR 113) from <a href="http://jsapi.sourceforge.net" rel="nofollow">here</a> (this link does not work now) or <a href="https://jcp.org/aboutJava/communityprocess/final/jsr113/index.html" rel="nofollow">here</a> following the examples of that library, I got java.lang.NullPointerException. The error was caused by the line "rec.allocate();". Why did it occur since the recognizer is assigned a line above ("rec = (Recognizer) EngineManager.createEngine(mode);")?</p>
  
  <p>The code is below:</p>
  
  <pre><code>import javax.speech.*;
  import javax.speech.recognition.*;
  ...    
  static Recognizer rec;
      ...
  public static void run(String[] args) {
              try {
                  RecognizerMode mode = new RecognizerMode(new SpeechLocale("en", "GB"));
                  rec = (Recognizer) EngineManager.createEngine(mode);
  
                  // Start up the recognizer
                  rec.allocate();
  
                  // Load the grammar, and enable it
                  String grammarMarkup = 
                      "&lt;grammar root='sentence' xml:lang='en' version='1.0' " +
                                   "xmlns='http://www.w3.org/2001/06/grammar'&gt;" + 
                        "&lt;rule id='sentence' scope='public'&gt;" +
                          "&lt;one-of&gt;" +
                            "&lt;item&gt; hello world &lt;/item&gt;" +
                            "&lt;item&gt; good morning &lt;/item&gt;" +
                            "&lt;item&gt; hello mighty computer &lt;/item&gt;" +
                          "&lt;/one-of&gt;" +
                        "&lt;/rule&gt;" +
                      "&lt;/grammar&gt;";
                  rec.getGrammarManager().loadGrammar("grammar:STT", null, grammarMarkup);
  
                  // Add the listener to get results
                  rec.addResultListener((ResultListener) new STT());
  
                  // Request focus and start listening
                  rec.requestFocus();
                  rec.resume();
  
                  rec.waitEngineState(Engine.DEALLOCATED); 
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
  </code></pre>