title: onCreateView Fragment layout in android
body: <p>I am using fragment layout, so I used <code>onCreateView</code> and then used the <code>onActivityCreated</code> method, but I am getting "APP Stopped Working".</p>
  
  <pre><code>package com.example.textspeech;
  
  public class Text extends Fragment{
  
     TextToSpeech t;
     private EditText write;
     Spinner spi;
     SeekBar sb;
     public Text(){}
  
     @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle   savedInstanceState) {
      View rootView = inflater.inflate(R.layout.text_to_speech, container, false);  
      return rootView;
  }
  
  public void onActivityCreated(Bundle savedInstanceState1) {
      super.onActivityCreated(savedInstanceState1);
      spi = (Spinner) getActivity().findViewById(R.id.spinner1);
      ArrayAdapter&lt;CharSequence&gt; apt =  ArrayAdapter.createFromResource(getActivity().getBaseContext(), R.array.name,android.R.layout.simple_list_item_single_choice);
  
        apt.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
        spi.setAdapter(apt);
        spi.setOnItemSelectedListener(new function1());
    write = (EditText) getActivity().findViewById(R.id.editText1);
  }
   @Override
     public void onPause(){
        if(t !=null){
           t.stop();
           t.shutdown();
        }
        super.onPause();
     }
  
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getActivity().getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
   @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         // Handle presses on the action bar items
         switch (item.getItemId()) {
             case R.id.action_settings:
                 return true;
             default:
                 return super.onOptionsItemSelected(item);
         }
     }
   public void speakText(View view){
        String toSpeak = write.getText().toString();
        t.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
  
     }
  
  
  
   public class function1 implements OnItemSelectedListener{
  
      @Override
      public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int pos,
              long arg3) {
          // TODO Auto-generated method stub
           if(pos==0){
               t=new TextToSpeech(getActivity(),new TextToSpeech.OnInitListener() {
                    @Override
                    public void onInit(int status) {
                       if(status != TextToSpeech.ERROR){
                           t.setLanguage(Locale.US);
                           t.setSpeechRate(1);
                           t.setPitch(1);
                          }               
                       }
                    });    
           }
      }
  
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
          // TODO Auto-generated method stub
      } 
   }
  }
  </code></pre>
  
  <p>here is Button xml </p>
  
  <pre><code>    &lt;Button
      android:id="@+id/button1"
      android:layout_width="240dp"
      android:layout_height="60dp"
      android:text="Speak"
      android:textColor="#AD2A10"
      android:textSize="35sp"
      android:onClick="speakText" /&gt;
  </code></pre>
  
  <p>Whenever I am pressing Button , so APP STOPPED RESPONDING.
  here is logcat</p>
  
  <pre><code>03-29 06:52:45.876: E/AndroidRuntime(816): FATAL EXCEPTION: main
  
  **03-29 06:52:45.876: E/AndroidRuntime(816): java.lang.IllegalStateException:  Could not find a method speakText(View) in the activity class  com.example.textspeech.MainActivity for onClick handler on view class  android.widget.Button with id 'button1'**
  03-29 06:52:45.876: E/AndroidRuntime(816):  at android.view.View$1.onClick(View.java:3620)
  03-29 06:52:45.876: E/AndroidRuntime(816):  at android.view.View.performClick(View.java:4240)
  03-29 06:52:45.876: E/AndroidRuntime(816):  at android.view.View$PerformClick.run(View.java:17721)
  03-29 06:52:45.876: E/AndroidRuntime(816):  at android.os.Handler.handleCallback(Handler.java:730)
  03-29 06:52:45.876: E/AndroidRuntime(816):  at android.os.Handler.dispatchMessage(Handler.java:92)
  03-29 06:52:45.876: E/AndroidRuntime(816):  at android.os.Looper.loop(Looper.java:137)
  03-29 06:52:45.876: E/AndroidRuntime(816):  at android.app.ActivityThread.main(ActivityThread.java:5103)
  03-29 06:52:45.876: E/AndroidRuntime(816):  at java.lang.reflect.Method.invokeNative(Native Method)
  03-29 06:52:45.876: E/AndroidRuntime(816):  at java.lang.reflect.Method.invoke(Method.java:525)
  03-29 06:52:45.876: E/AndroidRuntime(816):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
  03-29 06:52:45.876: E/AndroidRuntime(816):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  03-29 06:52:45.876: E/AndroidRuntime(816):  at dalvik.system.NativeStart.main(Native Method)
  03-29 06:52:45.876: E/AndroidRuntime(816): Caused by: java.lang.NoSuchMethodException: speakText [class android.view.View]
  03-29 06:52:45.876: E/AndroidRuntime(816):  at java.lang.Class.getConstructorOrMethod(Class.java:423)
  03-29 06:52:45.876: E/AndroidRuntime(816):  at java.lang.Class.getMethod(Class.java:787)
  03-29 06:52:45.876: E/AndroidRuntime(816):  at android.view.View$1.onClick(View.java:3613)
  </code></pre>
  
  <p>in this logcat I should get <strong>Could not find a method speakText(View) in the activity class com.example.textspeech.Text</strong>
  but I am getting <strong>Could not find a method speakText(View) in the activity class com.example.textspeech.MainActivity</strong></p>