title: APP Stopped responding in fragment layout
body: <p>I am using fragment layout and when I finish saying It Stopped working.
  what I need to add in this.</p>
  
  <pre><code>package com.example.textspeech;
  
  import java.util.ArrayList;
  import java.util.Locale;
  
  import javax.xml.transform.Result;
  
  import android.app.Activity;
  import android.app.Fragment;
  import android.content.ActivityNotFoundException;
  import android.content.Intent;
  import android.os.Bundle;
  import android.speech.RecognizerIntent;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ImageButton;
  import android.widget.TextView;
  import android.widget.Toast;
  import static android.app.Activity.RESULT_OK;
  
  public class Voice extends Fragment {
  //private static final int RESULT_OK = Activity.RESULT_OK;
  //private static final int RESULT_OK = 0;
  private TextView txtSpeechInput;
  private ImageButton btnSpeak;
  private final int REQ_CODE_SPEECH_INPUT = 100;
  
  public Voice(){}
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      View rootView = inflater.inflate(R.layout.voice_to_text, container, false);
      txtSpeechInput = (TextView) getActivity().findViewById(R.id.txtSpeechInput);
  
  
      // hide the action bar
      //getActivity().getActionBar().hide();
      return rootView;
  }
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onActivityCreated(savedInstanceState);
      btnSpeak = (ImageButton) getActivity().findViewById(R.id.btnSpeak);
      btnSpeak.setOnClickListener(new View.OnClickListener(){
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              //promptSpeechInput();
              Toast.makeText(getActivity(), "Say Something", 10000).show();
              promptSpeechInput();
  
          }
  
          private void promptSpeechInput() {
              // TODO Auto-generated method stub
              Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
              intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                      RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
              intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
              intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
                      getString(R.string.speech_prompt));
              try {
                  startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
              } catch (ActivityNotFoundException a) {
                  Toast.makeText(getActivity(),
                          getString(R.string.speech_not_supported),
                          Toast.LENGTH_SHORT).show();
              }
          }
      }); 
  }
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      switch (requestCode) {
      case REQ_CODE_SPEECH_INPUT : {
          if (resultCode ==RESULT_OK &amp;&amp; null != data) {
              Toast.makeText(getActivity(), "ok", 12345).show();
              ArrayList&lt;String&gt; result = data
                      .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
              txtSpeechInput.setText(result.get(0));
          }
          break;
      }
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>when I press button , google prompt open successfully but when i finish saying, App stopped responding.
  please help</p>