I am quite new to java programming and have been teaching myself through reading online and buying a few java programming books here and there.
However I am running into a problem when building a speech recognition program I have been working on for a few weeks now. It is giving me a nullpointer exception at the rec.addresultlistener
coding line and I have absoloutely no idea why, because to my knowledge that line is there to tell the program to listen for a input in order to check it against the grammar. This program was previously giving me the same errors for the rec.allocate()
coding line but that was fixed by declaring it null. Am I supposed to declare this as null as well?
Can someone please help me out here and also explain why?
//Create a recognizer that supports English
rec = Central.createRecognizer( new EngineModeDesc (Locale.ENGLISH));;
//Start up the recognizer
if(rec!=null){
rec.allocate();
//Load the grammar from a file, and enable it
System.out.println(new File(".").getAbsoluteFile());
FileReader reader = new FileReader("grammar2.0");
if (reader != null) System.out.println("no file");;
System.out.println(reader);
RuleGrammar gram = rec.loadJSGF(reader);
gram.setEnabled(true);
}
//Add the listener to get results
rec.addResultListener(new speech());
//commit the grammar
rec.commitChanges();
//Request focus and start listening
rec.requestFocus();
rec.resume();