title: Simple Math Game Crashes in AVD
body: <p>I'm building the Math Game from Chapters 2 and 3 of 'Learning Java by Building Android Games' by John Horton. I'm near the end of the 3rd chapter, and have coded exactly how the book suggests, but my game keeps crashing in my AVD. You don't have to have read the book to know what I'm talking about I don't believe, and I'm not looking for suggestions on how to improve my code, because the book is teaching the most basic aspects first, then delving into the more complex and concise methodologies. Basically, the objective of the game is to create an app that presents the user with a math problem, and give the user three options as to the answer of the questions.</p>
  
  <p>Here is my MainActivity.java:</p>
  
  <pre><code>package snzy.mathgamechapter2;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  
  public class MainActivity extends Activity implements View.OnClickListener{
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Button buttonPlay = (Button) findViewById(R.id.buttonPlay);
          buttonPlay.setOnClickListener(this);
      }
  
      @Override
      public void onClick (View view) {
  
          Intent i;
          i = new Intent(this, GameActivity.class);
          startActivity(i);
      }
  } 
  </code></pre>
  
  <p>Here is my GameActivity.java:</p>
  
  <pre><code>package snzy.mathgamechapter2;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.Button;
  import android.widget.TextView;
  
  public class GameActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_game);
          int partA = 9;
          int partB = 9;
          int correctAnswer = partA*partB;
          int wrongAnswer1 = correctAnswer - 1;
          int wrongAnswer2 = correctAnswer + 1;
  
          TextView textObjectPartA =
                  (TextView)findViewById(R.id.textPartA);
          TextView textObjectPartB =
                  (TextView)findViewById(R.id.textPartB);
          Button buttonObjectChoice1 =
                  (Button)findViewById(R.id.buttonChoice1);
          Button buttonObjectChoice2 =
                  (Button) findViewById(R.id.buttonChoice2);
          Button buttonObjectChoice3 =
                  (Button) findViewById(R.id.buttonChoice3);
  
          textObjectPartA.setText("" + partA);
          textObjectPartB.setText("" + partB);
          buttonObjectChoice1.setText("" +correctAnswer);
          buttonObjectChoice2.setText("" + wrongAnswer1);
          buttonObjectChoice3.setText("" + wrongAnswer2);
  
      }
  }
  </code></pre>
  
  <p>Here is my logcat:</p>
  
  <pre><code>&gt; 06-06 15:46:41.038 6951-6951/? I/art: Not late-enabling -Xcheck:jni
  &gt; (already on) 06-06 15:46:41.139 6951-6951/snzy.mathgamechapter2
  &gt; W/System: ClassLoader referenced unknown path:
  &gt; /data/app/snzy.mathgamechapter2-2/lib/x86 06-06 15:46:41.245
  &gt; 6951-6951/snzy.mathgamechapter2 D/AndroidRuntime: Shutting down VM
  &gt; 06-06 15:46:41.276 6951-6951/snzy.mathgamechapter2 E/AndroidRuntime:
  &gt; FATAL EXCEPTION: main
  &gt;                                                                            Process: snzy.mathgamechapter2, PID: 6951
  &gt;                                                                            java.lang.RuntimeException: Unable to start activity
  &gt; ComponentInfo{snzy.mathgamechapter2/snzy.mathgamechapter2.MainActivity}:
  &gt; java.lang.ClassCastException: android.widget.RelativeLayout cannot be
  &gt; cast to android.widget.Button
  &gt;                                                                                at
  &gt; android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
  &gt;                                                                                at
  &gt; android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
  &gt;                                                                                at android.app.ActivityThread.-wrap11(ActivityThread.java)
  &gt;                                                                                at
  &gt; android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
  &gt;                                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
  &gt;                                                                                at android.os.Looper.loop(Looper.java:148)
  &gt;                                                                                at android.app.ActivityThread.main(ActivityThread.java:5417)
  &gt;                                                                                at java.lang.reflect.Method.invoke(Native Method)
  &gt;                                                                                at
  &gt; com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  &gt;                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  &gt;                                                                             Caused by: java.lang.ClassCastException: android.widget.RelativeLayout
  &gt; cannot be cast to android.widget.Button
  &gt;                                                                                at snzy.mathgamechapter2.MainActivity.onCreate(MainActivity.java:15)
  &gt;                                                                                at android.app.Activity.performCreate(Activity.java:6237)
  &gt;                                                                                at
  &gt; android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
  &gt;                                                                                at
  &gt; android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
  &gt;                                                                                at
  &gt; android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
  &gt;                                                                                at android.app.ActivityThread.-wrap11(ActivityThread.java) 
  &gt;                                                                                at
  &gt; android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
  &gt;                                                                                at android.os.Handler.dispatchMessage(Handler.java:102) 
  &gt;                                                                                at android.os.Looper.loop(Looper.java:148) 
  &gt;                                                                                at android.app.ActivityThread.main(ActivityThread.java:5417) 
  &gt;                                                                                at java.lang.reflect.Method.invoke(Native Method) 
  &gt;                                                                                at
  &gt; com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
  &gt;                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  06-06
  &gt; 15:46:55.432 6951-6951/? I/Process: Sending signal. PID: 6951 SIG: 9
  </code></pre>
  
  <p>Any help would be much appreciated.</p>
  
  <p>Here is my activity_main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout  
      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="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"
      tools:context="snzy.mathgamechapter2.MainActivity"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay"&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;include layout="@layout/content_main"
          android:id="@+id/buttonPlay" /&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>Here is my content_main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout 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="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      tools:context="baylamafia.mathgamechapter2.MainActivity"
      tools:showIn="@layout/activity_main"&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:text="My Math game"
          android:id="@+id/textView"
          android:textSize="30sp"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true" /&gt;
  
      &lt;ImageView
          android:layout_width="150dp"
          android:layout_height="150dp"
          android:id="@+id/imageView"
          android:layout_below="@+id/textView"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="12dp" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Play"
          android:id="@+id/button"
          android:layout_below="@+id/imageView"
          android:layout_marginTop="17dp"
          android:layout_alignEnd="@+id/button2"
          android:layout_alignStart="@+id/button2" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="High Scores"
          android:id="@+id/button2"
          android:layout_below="@+id/button"
          android:layout_centerHorizontal="true" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Quit"
          android:id="@+id/button3"
          android:layout_below="@+id/button2"
          android:layout_alignEnd="@+id/button2"
          android:layout_alignStart="@+id/button2" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>