title: Text to speech class not working
body: <p>Hi i am a newbie in android development. My Text to speech class in not working. Eclipse is giving the mentioned error below and i have pasted by Text to speech class code also. Thanks for helping</p>
  
  <pre><code>03-25 20:37:49.046: E/AndroidRuntime(31160): FATAL EXCEPTION: main
  03-25 20:37:49.046: E/AndroidRuntime(31160): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sms_reader/com.example.sms_reader.Texttospeech}: java.lang.NullPointerException
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at android.app.ActivityThread.access$600(ActivityThread.java:165)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at android.os.Handler.dispatchMessage(Handler.java:107)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at android.os.Looper.loop(Looper.java:194)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at android.app.ActivityThread.main(ActivityThread.java:5391)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at java.lang.reflect.Method.invokeNative(Native Method)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at java.lang.reflect.Method.invoke(Method.java:525)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at dalvik.system.NativeStart.main(Native Method)
  03-25 20:37:49.046: E/AndroidRuntime(31160): Caused by: java.lang.NullPointerException
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at com.example.sms_reader.Texttospeech.speakOut(Texttospeech.java:33)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at com.example.sms_reader.Texttospeech.onCreate(Texttospeech.java:26)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at android.app.Activity.performCreate(Activity.java:5122)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
  03-25 20:37:49.046: E/AndroidRuntime(31160):    ... 11 more
  </code></pre>
  
  <p>Texttospeech.java</p>
  
  <pre><code>package com.example.sms_reader;
  
  import java.util.Locale;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.speech.tts.TextToSpeech;
  import android.util.Log;
  
  public class Texttospeech extends Activity implements
  TextToSpeech.OnInitListener
  {
  
  TextToSpeech tts;
  String content;
  
  protected void onCreate(Bundle savedInstanceState) {
      Log.d("tag4", "INTENT RECEIVED");
      Intent data = getIntent();
      Log.d("tag5", "INTENT ");
      String msg = data.getStringExtra("msg");
      String from = data.getStringExtra("from");
      content = "You have received a message from" +from +"and it says"+msg;
      Log.d("tag6", content);
      speakOut(); 
  
  };
  
  private void speakOut() {
  
  
      tts.speak(content, TextToSpeech.QUEUE_FLUSH, null);
  }   
  
  @Override
  public void onDestroy() {
      // Don't forget to shutdown!
      if (tts != null) {
          tts.stop();
          tts.shutdown();
      }
      super.onDestroy();
  }
  
  @Override
  public void onInit(int status) {
      // TODO Auto-generated method stub
  
      if (status == TextToSpeech.SUCCESS) {
  
          int result = tts.setLanguage(Locale.US);
  
          // tts.setPitch(5); // set pitch level
  
          // tts.setSpeechRate(2); // set speech speed rate
  
          if (result == TextToSpeech.LANG_MISSING_DATA
                  || result == TextToSpeech.LANG_NOT_SUPPORTED) {
              Log.e("TTS", "Language is not supported");
          } 
          else {
  
              speakOut();
          }
  
                                           } 
      else 
      {
          Log.e("TTS", "Initilization Failed");
      }
  
  }
  }
  </code></pre>