I created a TTS module. It was working perfectly on a stand alone basis but when I tried implementing it as a class for my project it misbehaves and throws null pointer exception.
What I plan to achieve:
1) Read a text file from /res/raw folder.
2) convert the text file into speech via TTS. The string s has captured the whole file via the BufferReader class.
The code I have used for TTS is –
private TextToSpeech tts;
tts.speak(s, TextToSpeech.QUEUE_FLUSH, null);
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
The error comes on the tts.speak….. line. I found out this line by adding log.d throughout the code. There is no log.d registered post the above tts.speak code.
Please help me in debugging the issue.
thanks a ton in advance.
You’ve shown declaring the variable:
… and you’ve shown using the variable:
… but do you ever initialize the variable? If you don’t assign it a value, it will always have the default value of
null. Judging by this tutorial you need something like this (I’m assuming your code is in anActivity):