title: How to solve error: Could not find method onClick(View) in a parent or ancestor Context for android:onClick
body: <p>I have seen that there's been some similar questions but the answers to those haven't helped me so far. The full error:</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: Could not find method onClick(View)
    in a parent  or ancestor Context for android:onClick attribute defined
    on view class android.support.v7.widget.AppCompatButton with id
    'button_random'</p>
  </blockquote>
  
  <p>The class (<strong>StartActivity.java</strong>):</p>
  
  <pre><code>public class StartActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_start);
      }
  
      public void onClick(View v) {
          Log.d("DEBUG", "CLICKED " + v.getId());
      }
  
  }
  </code></pre>
  
  <p>The XML (<strong>activity_start.xml</strong>):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Random Game"
          android:id="@+id/button_random"
          android:layout_gravity="center_horizontal"
          android:onClick="onClick" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I have added the activity to the AndroidManifest.xml. I have similar activities that work in the same way and I don't have any problems with those...</p>
  
  <p>Does anyone see something where I am missing something or have made a mistake?</p>