title: Not able to get Text-to-Speech work from an non-activity class
body: <p>I tried to use Text-to-Speech but getting an nullpointerexception.I have many textviews with text init.what i tried to do is that when user clicks on this textviews than text-to-speech speaks up the text which is on that particular textview.Following is the code of 2 of my classes which handles text-to-speech.I have also marked down the lines where i'm getting the nullpointerexception.Please tell me what am i doing wrong?! Thank you. </p>
  
  <p>My TextSpeaker class:</p>
  
  <pre><code>public class TextSpeaker implements OnInitListener{
  
  TextToSpeech tts;
  public TextSpeaker(Context c,OnInitListener listener){
      tts = new TextToSpeech(c,listener); //Getting NullPointerException here
  }
  
  @Override
  public void onInit(int status) {
      if(status != TextToSpeech.ERROR){
          tts.setLanguage(Locale.US);
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My TextViewClick class:</p>
  
  <pre><code>public class TextViewClick implements OnClickListener{
  public String textHolder;
  Context c;
  TextToSpeech.OnInitListener listener;
  TextSpeaker tts1 = new TextSpeaker(c,listener); //Getting NullPointerException here
  @Override
  public void onClick(View v) {
      TextView tv=(TextView) v;
      tv.setTextColor(R.color.red);
      textHolder = (String) tv.getText();
      System.out.println(textHolder);
      tts1.tts.speak(textHolder, TextToSpeech.QUEUE_FLUSH, null);
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My logcat messages:</p>
  
  <pre><code>01-18 13:59:20.017: E/AndroidRuntime(323): FATAL EXCEPTION: main
  01-18 13:59:20.017: E/AndroidRuntime(323): java.lang.NullPointerException
  01-18 13:59:20.017: E/AndroidRuntime(323):  at android.speech.tts.TextToSpeech.&lt;init&gt;(TextToSpeech.java:407)
  01-18 13:59:20.017: E/AndroidRuntime(323):  at blah.blah.com.TextSpeaker.&lt;init&gt;(TextSpeaker.java:13)
  01-18 13:59:20.017: E/AndroidRuntime(323):  at independent.vervecoders.com.TextViewClick.&lt;init&gt;(TextViewClick.java:13)
  01-18 13:59:20.017: E/AndroidRuntime(323):  at independent.vervecoders.com.Independent.onClick(Independent.java:86)
  01-18 13:59:20.017: E/AndroidRuntime(323):  at android.view.View.performClick(View.java:2408)
  01-18 13:59:20.017: E/AndroidRuntime(323):  at android.view.View$PerformClick.run(View.java:8816)
  01-18 13:59:20.017: E/AndroidRuntime(323):  at android.os.Handler.handleCallback(Handler.java:587)
  01-18 13:59:20.017: E/AndroidRuntime(323):  at android.os.Handler.dispatchMessage(Handler.java:92)
  01-18 13:59:20.017: E/AndroidRuntime(323):  at android.os.Looper.loop(Looper.java:123)
  01-18 13:59:20.017: E/AndroidRuntime(323):  at android.app.ActivityThread.main(ActivityThread.java:4627)
  01-18 13:59:20.017: E/AndroidRuntime(323):  at java.lang.reflect.Method.invokeNative(Native Method)
  01-18 13:59:20.017: E/AndroidRuntime(323):  at java.lang.reflect.Method.invoke(Method.java:521)
  01-18 13:59:20.017: E/AndroidRuntime(323):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  01-18 13:59:20.017: E/AndroidRuntime(323):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  01-18 13:59:20.017: E/AndroidRuntime(323):  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>