IllegalStateException when trying to add method to button click in Android Studio : <p>I'm creating a simple app that will generate workout routines every time i go to the gym. </p>

<p>Each time I call the method to generate a String of workouts I get an IllegalStateException </p>

<p>Here is my second display xml (where I want the generated String valued workouts to display)</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="1"&gt;

    &lt;android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="0dp"&gt;

        &lt;Button
            android:id="@+id/button6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="createRandomBicepWorkOut"
            android:text="Generate"
            tools:layout_constraintRight_creator="1"
            tools:layout_constraintBottom_creator="1"
            app:layout_constraintBottom_toTopOf="@+id/textView3"
            app:layout_constraintRight_toRightOf="parent"
            tools:layout_constraintLeft_creator="1"
            android:layout_marginBottom="146dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintHorizontal_bias="0.0" /&gt;

        &lt;TextView
            android:id="@+id/textView3"
            android:layout_width="420dp"
            android:layout_height="291dp"
            android:text="TextView"
            tools:layout_constraintTop_creator="1"
            tools:layout_constraintRight_creator="1"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_marginTop="254dp"
            tools:layout_constraintLeft_creator="1"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            tools:layout_editor_absoluteY="255dp" /&gt;
    &lt;/android.support.constraint.ConstraintLayout&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>Here is my second display java file in which i have the algorithm to generate the workouts.</p>

<pre><code>public class SecondDisplay extends Activity {


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.seconddisplay); //xml file name
    }
    private TextView bicepResults;
    public String createRandomBicepWorkOut(){
        Random ran = new Random();
        String[] bicepArray = new String[3];
        String one = "curls";
        String two = "preacher curls";
        String three = "hammer curls";
        String four = "barbell curls";
        String five = "decline curls";
        String six = "elliptical curls";

        for(int i = 0; i &lt; bicepArray.length;i++){
            int index = ran.nextInt(5)+1;
            if(index == 1)
                bicepArray[i] = one;
            else if(index == 2)
                bicepArray[i] = two;
            else if(index == 3)
                bicepArray[i] = three;
            else if(index == 4)
                bicepArray[i] = four;
            else if(index == 5)
                bicepArray[i] = five;
            else if(index == 6)
                bicepArray[i] = six;
        }
        bicepResults = (TextView) findViewById(R.id.textView3);
        for(int i = 0; i &lt; bicepArray.length; i++){
            bicepResults.setText(bicepArray[i]);
        }
        return "gains";
    }
}
</code></pre>

<p>Here is my logcat</p>

<pre><code>                   05-23 23:03:00.328 2686-2686/com.example.ghost.newapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                    Process: com.example.ghost.newapp, PID: 2686
                                                                    java.lang.IllegalStateException: Could not find method createRandomBicepWorkOut(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.widget.Button with id 'button6'
                                                                        at android.view.View$DeclaredOnClickListener.resolveMethod(View.java:4730)
                                                                        at android.view.View$DeclaredOnClickListener.onClick(View.java:4689)
                                                                        at android.view.View.performClick(View.java:5610)
                                                                        at android.view.View$PerformClick.run(View.java:22265)
                                                                        at android.os.Handler.handleCallback(Handler.java:751)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                        at android.os.Looper.loop(Looper.java:154)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
</code></pre>
