Question: In Android, if a TextToSpeech instance fails to initialize (the callback invoked indicating the completion of the TextToSpeech engine initialization returns TextToSpeech.ERROR), does that mean that subsequent attempted method calls to that instance will result in null pointer exceptions?

Example...

We initialize the object:

```
t1 = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if (status == TextToSpeech.ERROR) {
                    Log.i("XXX", "There was an error initializing the TTS");
                }
            }
        });

```

... let's say the init fails, but we then go on to do something like:

```
t1.speak("hello");

```

Will this crash... or just say nothing? The reason I ask is that if it does crash, then obviously I would have to put null checks everywhere.

Also, the reason I can't just find out for myself is that I don't know how to simulate the error.

Thanks for any prior knowledge.

Answer: 
I had this problem, then I noticed that on some devices TTS may be deactivated. So I've just done the following

```
try {
        Intent intent = new Intent();
        intent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
        startActivityForResult(intent, 0);
    } catch(ActivityNotFoundException exception) {
        Uri uri = Uri.parse("market://details?id=" + "com.google.android.tts&hl=fr");
        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
        goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
        try {
            startActivity(goToMarket);
        } catch (ActivityNotFoundException e) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + "com.google.android.tts&hl=fr")));
        }
    } 

```
You can try with this code.

Use `language_codes` from <https://www.w3schools.com/tags/ref_language_codes.asp>.

```
mLanguage = new Locale(language_codes);

tts = new TextToSpeech(mContext, new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                int result = tts.setLanguage(mLanguage);
                if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                    Log.e("Text2SpeechWidget", result + " is not supported");
                }
            }
        }
    });

```