title: TTS (Text to Speech): manager in own class
body: <p>i'm trying to get build a Text to Speech Manager within an own manager class.</p>
  
  <p>Currently my code looks like this:</p>
  
  <pre><code>public class TTSManager extends Activity implements OnInitListener{
  
  private TextToSpeech myTTS;
  private int MY_DATA_CHECK_CODE = 0;
  private boolean readyToSpeak = false;
  
  public TTSManager()
  {
      ;
  }
  
  public void checkIfTTSModulesInstalled()
  {
      Intent checkIntent = new Intent();
      checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
      startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
  }
  
  
  protected void onActivityResult(
          int requestCode, int resultCode, Intent data) {
      if (requestCode == MY_DATA_CHECK_CODE) {
          if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) 
          {
              // success, create the TTS instance
              myTTS = new TextToSpeech(this, this);
          } 
          else 
          {
              // missing data, install it
              Intent installIntent = new Intent();
              installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
              startActivity(installIntent);
          }
      }
  }
  
  
  @Override
  public void onInit(int status) 
  {
      if (status == TextToSpeech.SUCCESS)
      {
          if(myTTS.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE)
          {
              myTTS.setLanguage(Locale.US);
              readyToSpeak = true;
          }
      }
  }
  
  public void speak(String text)
  {
      if (readyToSpeak)
          myTTS.speak(text, TextToSpeech.QUEUE_FLUSH, null);
  }
  
  }
  </code></pre>
  
  <p>Unfortunately i'm receiving a null pointer exception when trying to initialize the TTS module.
  How can i build a TTS Manager is an own class (and not directly within the activity where the TTS should be used)?</p>