title: Android unable to find my onClick method
body: <p>I am having an issue where my Button (id <code>i_am_a_problem</code>) which is declared in the fragment's layout XML, is generating an error when the button is clicked. Android tries to call the onClick method <code>public void calculate(View v)</code> but is unable to find it (despite it being declared in MainActivity). Details of my code are below, and the error is after that. Please help me determine why android is unable to find the onClick method. Thanks.</p>
  
  <p>There is really not anything else going on in this code (fresh new project)</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>package supercali.FRAG.alistic;
  
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.TextView;
  
  public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) { /*snip - irrelevance*/ }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) { /*snip - irrelevance*/ }
  
      public void calculcate(View v){
          TextView tv = (TextView)findViewById(R.id.results);
          tv.setText(calculate_value());
      }
  
      private String calculate_value(){
          return "Abra Kadabra";
      }
  }
  </code></pre>
  
  <p>MainActivity's layout just contains a fragment</p>
  
  <pre><code>&lt;fragment
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fragment"
    android:name="supercali.FRAG.alistic.MainActivityFragment" 
    tools:layout="@layout/fragment_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" /&gt;
  </code></pre>
  
  <p>And the layout for that Fragment is:</p>
  
  <pre><code>&lt;LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivityFragment"&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/calculate"
          android:onClick="calculate"
          android:id="@+id/i_am_a_problem"/&gt;
  
      &lt;TextView android:text="@string/results_pending" android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:id="@+id/results"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>The problem Button is just there ^^ with id i_am_a_problem</strong></p>
  
  <p>LogCat:</p>
  
  <pre><code>06-18 09:49:41.280  31642-31642/supercali.FRAG.alistic E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: supercali.FRAG.alistic, PID: 31642
      java.lang.IllegalStateException: Could not find method calculate(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton
              at android.view.View$DeclaredOnClickListener.resolveMethod(View.java:4441)
              at android.view.View$DeclaredOnClickListener.onClick(View.java:4405)
              at android.view.View.performClick(View.java:5147)
              at android.view.View$PerformClick.run(View.java:21069)
              at android.os.Handler.handleCallback(Handler.java:739)
              at android.os.Handler.dispatchMessage(Handler.java:95)
              at android.os.Looper.loop(Looper.java:148)
              at android.app.ActivityThread.main(ActivityThread.java:5401)
              at java.lang.reflect.Method.invoke(Native Method)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:725)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:615)
  </code></pre>