java.lang.NullPointerException for JSAPI Speech Recognizer in Java -


while tried simple speech recognizer jsapi (jsr 113) here (this link not work now) or here following examples of library, got java.lang.nullpointerexception. error caused line "rec.allocate();". why did occur since recognizer assigned line above ("rec = (recognizer) enginemanager.createengine(mode);")?

the code below:

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 recognizer                 rec.allocate();                  // load grammar, , enable                 string grammarmarkup =                      "<grammar root='sentence' xml:lang='en' version='1.0' " +                                  "xmlns='http://www.w3.org/2001/06/grammar'>" +                        "<rule id='sentence' scope='public'>" +                         "<one-of>" +                           "<item> hello world </item>" +                           "<item> morning </item>" +                           "<item> hello mighty computer </item>" +                         "</one-of>" +                       "</rule>" +                     "</grammar>";                 rec.getgrammarmanager().loadgrammar("grammar:stt", null, grammarmarkup);                  // add listener results                 rec.addresultlistener((resultlistener) new stt());                  // request focus , start listening                 rec.requestfocus();                 rec.resume();                  rec.waitenginestate(engine.deallocated);              } catch (exception e) {                 e.printstacktrace();             }         } 


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -