title: java.lang.RuntimeException: Unable to instantiate activit
body: <p>I'm trying to write an Android app that logs when you click a button it will put text into the console, however I am getting an error when I complie it and run it on my Galaxy S7 edge running 7.0 API version 24.</p>
  
  <p><a href="https://stackoverflow.com/questions/4688277/java-lang-runtimeexception-unable-to-instantiate-activity-componentinfo">I've read that I need to add something into the manifest file</a> however I am not sure what I need to add.</p>
  
  <blockquote>
    <p>FATAL EXCEPTION: main
                                                                                  Process: me.adamstephenson.test.test1, PID: 16405
                                                                                  java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{me.adamstephenson.test.test1/me.adamstephenson.test.test1.MainActivity}: java.lang.ClassCastException: me.adamstephenson.test.test1.MainActivity cannot be cast to android.app.Activity</p>
  </blockquote>
  
  <pre><code>package me.adamstephenson.test.test1;
  import android.app.Activity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  
  public class MainActivity {
      public class MyActivity extends Activity {
          protected void onCreate(Bundle icicle) {
              super.onCreate(icicle);
  
              setContentView(R.layout.activity_main);
  
              final Button button = (Button) findViewById(R.id.RequestKey);
              button.setOnClickListener(new View.OnClickListener() {
                  public void onClick(View v) {
                      Log.d("RequestKey", "Clicked");
                  }
              });
          }
      }
  }
  </code></pre>
  
  <p><a href="https://developer.android.com/reference/android/widget/Button.html" rel="nofollow noreferrer">Source</a></p>
  
  <p>Here is the layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout 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"
  tools:context="me.adamstephenson.test.test1.MainActivity"&gt;
  
  &lt;Button
      android:id="@+id/RequestKey"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Button"
      tools:layout_editor_absoluteX="196dp"
      tools:layout_editor_absoluteY="129dp" /&gt;
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>Finally here is the manifest file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="me.adamstephenson.test.test1"&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity android:name=".MainActivity"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>