title: Changing xml activity on button click
body: <p>I'm having issues getting the activities to change on button click. I've been following a youtube video, but I don't know why it's not working for me. When you click the button, the app crashes. Here's what I have. </p>
  
  <p>MainActivity.java</p>
  
  <pre><code>package com.example.andy.design;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.View;
  import android.widget.Button;
  
  public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  Button btnSimple = (Button) findViewById(R.id.btnSimple);
          btnSimple.setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View v) {
  
                  Intent intent = new Intent(v.getContext(), Activity2.class);
                  startActivityForResult(intent, 0);
              }
  
          });
  
  
     //    public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
        //  getMenuInflater().inflate(R.menu.menu_main, menu);
        //  return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p>Activity2.java</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  
  public class Activity2 extends Activity {
  
  
      public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
          setContentView(R.layout.activity2);
  
      }
  
  
  }
  </code></pre>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;GridLayout
      android:layout_width="402dp"
      android:layout_height="match_parent"
      android:layout_row="5"
      android:layout_column="0"
      xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
  
  
  
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="New Button"
          android:id="@+id/btnSimple"
          android:layout_row="15"
          android:layout_column="11" /&gt;
  
  
      &lt;/GridLayout&gt;
  </code></pre>
  
  <p>Logcat</p>
  
  <pre><code> 02-01 23:16:19.500 2274-2274/com.example.andy.design I/art: Not late-enabling -Xcheck:jni (already on)
  02-01 23:16:19.563 2274-2274/com.example.andy.design W/System: ClassLoader referenced unknown path: /data/app/com.example.andy.design-1/lib/x86
  02-01 23:16:19.759 2274-2297/com.example.andy.design D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
  02-01 23:16:19.824 2274-2297/com.example.andy.design I/OpenGLRenderer: Initialized EGL, version 1.4
  02-01 23:16:20.163 2274-2297/com.example.andy.design W/EGL_emulation: eglSurfaceAttrib not implemented
  02-01 23:16:20.163 2274-2297/com.example.andy.design W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xabfa1a60, error=EGL_SUCCESS
  02-01 23:16:20.462 2274-2274/com.example.andy.design I/Choreographer: Skipped 40 frames!  The application may be doing too much work on its main thread.
  02-01 23:16:25.521 2274-2274/com.example.andy.design D/AndroidRuntime: Shutting down VM
  02-01 23:16:25.522 2274-2274/com.example.andy.design E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: com.example.andy.design, PID: 2274
                                                                         java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.andy.design/com.example.andy.design.Activity2}: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class activity
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                             at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                             at android.os.Looper.loop(Looper.java:148)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                          Caused by: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class activity
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                                                                             at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
                                                                             at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
                                                                             at com.example.andy.design.Activity2.onCreate(Activity2.java:16)
                                                                             at android.app.Activity.performCreate(Activity.java:6237)
                                                                             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                             at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                             at android.os.Looper.loop(Looper.java:148) 
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                             at java.lang.reflect.Method.invoke(Native Method) 
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                          Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class activity
                                                                             at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
                                                                             at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                                             at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                                                                             at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                             at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
                                                                             at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
                                                                             at com.example.andy.design.Activity2.onCreate(Activity2.java:16) 
                                                                             at android.app.Activity.performCreate(Activity.java:6237) 
                                                                             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                             at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                             at android.os.Looper.loop(Looper.java:148) 
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                             at java.lang.reflect.Method.invoke(Native Method) 
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                          Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.activity" on path: DexPathList[[zip file "/data/app/com.example.andy.design-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.andy.design-1/lib/x86, /vendor/lib, /system/lib]]
                                                                             at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                             at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                                                             at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                                                             at android.view.LayoutInflater.createView(LayoutInflater.java:583)
                                                                             at android.view.LayoutInflater.onCreateView(LayoutInflater.java:677)
                                                                             at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
                                                                             at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
                                                                             at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
                                                                             at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                                             at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                                                                             at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                             at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
                                                                             at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
                                                                             at com.example.andy.design.Activity2.onCreate(Activity2.java:16) 
                                                                             at android.app.Activity.performCreate(Activity.java:6237) 
                                                                             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                             at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                             at android.os.Looper.loop(Looper.java:148) 
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                             at java.lang.reflect.Method.invoke(Native Method) 
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                          Suppressed: java.lang.ClassNotFoundException: android.view.activity
                                                                             at java.lang.Class.classForName(Native Method)
                                                                             at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                                                                             at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                                                                             at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                                                                                  ... 27 more
                                                                          Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
  </code></pre>
  
  <p>Android Manifest</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.andy.design"&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name"
              android:theme="@style/AppTheme.NoActionBar"&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;activity android:name=".Activity2"
          android:label="Activity Two"/&gt;
  </code></pre>
  
  <p></p>