title: Android problems when creating new activity: Unable to start activity ComponentInfo
body: <p>Hello I'm trying to create a popupmenu when I click a button through a new activity but I have always the same problem and I searched for a solution but I cant see it by myself. Maybe it's something stupid that I'm doing but I started a few days with Android.</p>
  
  <p>The logcat is this:</p>
  
  <pre><code>03-14 11:46:37.581 9653-9653/info.androidhive.navigationdrawer E/AndroidRuntime: FATAL EXCEPTION: main
  Process: info.androidhive.navigationdrawer, PID: 9653
  java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.navigationdrawer/info.androidhive.navigationdrawer.activity.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
   at android.app.ActivityThread.access$800(ActivityThread.java:151)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:135)
   at android.app.ActivityThread.main(ActivityThread.java:5254)
   at java.lang.reflect.Method.invoke(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
   at android.view.LayoutInflater.createView(LayoutInflater.java:633)
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
   at android.view.LayoutInflater.parseInclude(LayoutInflater.java:892)
   at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
   at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
   at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
   at info.androidhive.navigationdrawer.activity.MainActivity.onCreate(MainActivity.java:69)
   at android.app.Activity.performCreate(Activity.java:5990)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
   at android.app.ActivityThread.access$800(ActivityThread.java:151) 
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
   at android.os.Handler.dispatchMessage(Handler.java:102) 
   at android.os.Looper.loop(Looper.java:135) 
   at android.app.ActivityThread.main(ActivityThread.java:5254) 
   at java.lang.reflect.Method.invoke(Native Method) 
   at java.lang.reflect.Method.invoke(Method.java:372) 
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
  Caused by: java.lang.reflect.InvocationTargetException
   at java.lang.reflect.Constructor.newInstance(Native Method)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
   at android.view.LayoutInflater.createView(LayoutInflater.java:607)
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
   at android.view.LayoutInflater.parseInclude(LayoutInflater.java:892) 
   at android.view.LayoutInflater.rInflate(LayoutInflater.java:802) 
   at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
   at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
   at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
   at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
   at info.androidhive.navigationdrawer.activity.MainActivity.onCreate(MainActivity.java:69) 
   at android.app.Activity.performCreate(Activity.java:5990) 
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
   at android.app.ActivityThread.access$800(ActivityThread.java:151) 
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
   at android.os.Handler.dispatchMessage(Handler.java:102) 
   at android.os.Looper.loop(Looper.java:135) 
   at android.app.ActivityThread.main(ActivityThread.java:5254) 
   at java.lang.reflect.Method.invoke(Native Method) 
   at java.lang.reflect.Method.invoke(Method.java:372) 
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
  Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
   at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:36)
   at android.support.design.widget.CoordinatorLayout.&lt;init&gt;(CoordinatorLayout.java:185)
   at android.support.design.widget.CoordinatorLayout.&lt;init&gt;(CoordinatorLayout.java:179)
   at java.lang.reflect.Constructor.newInstance(Native Method) 
   at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
   at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
   at android.view.LayoutInflater.parseInclude(LayoutInflater.java:892) 
   at android.view.LayoutInflater.rInflate(LayoutInflater.java:802) 
   at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
   at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
   at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
   at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
   at info.androidhive.navigationdrawer.activity.MainActivity.onCreate(MainActivity.java:69) 
   at android.app.Activity.performCreate(Activity.java:5990) 
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
   at android.app.ActivityThread.access$800(ActivityThread.java:151) 
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
   at android.os.Handler.dispatchMessage(Handler.java:102) 
   at android.os.Looper.loop(Looper.java:135) 
   at android.app.ActivityThread.main(ActivityThread.java:5254) 
   at java.lang.reflect.Method.invoke(Native Method) 
   at java.lang.reflect.Method.invoke(Method.java:372) 
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  </code></pre>
  
  <p>My MainActivity:</p>
  
  <pre><code>package info.androidhive.navigationdrawer.activity;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.os.Handler;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.NavigationView;
  import android.support.design.widget.Snackbar;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentTransaction;
  import android.support.v4.view.GravityCompat;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v7.app.ActionBarDrawerToggle;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.Button;
  import android.widget.ImageView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import com.bumptech.glide.Glide;
  import com.bumptech.glide.load.engine.DiskCacheStrategy;
  
  import info.androidhive.navigationdrawer.R;
  import info.androidhive.navigationdrawer.fragment.GenerarFragment;
  import info.androidhive.navigationdrawer.fragment.PasswordsFragment;
  import info.androidhive.navigationdrawer.fragment.SettingsFragment;
  import info.androidhive.navigationdrawer.other.CircleTransform;
  
  public class MainActivity extends AppCompatActivity {
  
      private NavigationView navigationView;
      private DrawerLayout drawer;
      private View navHeader;
      private ImageView imgNavHeaderBg, imgProfile;
      private TextView txtName, txtWebsite;
      private Toolbar toolbar;
      private FloatingActionButton fab;
  
      // urls to load navigation header background image
      // and profile image
      private static final String urlNavHeaderBg = "http://api.androidhive.info/images/nav-menu-header-bg.jpg";
      private static final String urlProfileImg = "https://lh3.googleusercontent.com/eCtE_G34M9ygdkmOpYvCag1vBARCmZwnVS6rS5t4JLzJ6QgQSBquM0nuTsCpLhYbKljoyS-txg";
  
      // index to identify current nav menu item
      public static int navItemIndex = 0;
  
      // tags used to attach the fragments
      private static final String TAG_HOME = "home";
      private static final String TAG_PHOTOS = "photos";
      private static final String TAG_SETTINGS = "settings";
      public static String CURRENT_TAG = TAG_HOME;
  
      // toolbar titles respected to selected nav menu item
      private String[] activityTitles;
  
      // flag to load home fragment when user presses back key
      private boolean shouldLoadHomeFragOnBackPress = true;
      private Handler mHandler;
  
      private static Button button_sbm;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          mHandler = new Handler();
  
          drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          navigationView = (NavigationView) findViewById(R.id.nav_view);
          fab = (FloatingActionButton) findViewById(R.id.fab);
  
          // Navigation view header
          navHeader = navigationView.getHeaderView(0);
          txtName = (TextView) navHeader.findViewById(R.id.name);
          txtWebsite = (TextView) navHeader.findViewById(R.id.website);
          imgNavHeaderBg = (ImageView) navHeader.findViewById(R.id.img_header_bg);
          imgProfile = (ImageView) navHeader.findViewById(R.id.img_profile);
  
          // load toolbar titles from string resources
          activityTitles = getResources().getStringArray(R.array.nav_item_activity_titles);
  
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                          .setAction("Action", null).show();
              }
          });
  
          // load nav menu header data
          loadNavHeader();
  
          // initializing navigation menu
          setUpNavigationView();
  
          if (savedInstanceState == null) {
              navItemIndex = 0;
              CURRENT_TAG = TAG_HOME;
              loadHomeFragment();
          }
          OnClickButtonListener();
      }
  
      public void OnClickButtonListener(){
          button_sbm = (Button) findViewById(R.id.button);
          button_sbm.setOnClickListener(
                  new View.OnClickListener(){
                      @Override
                      public void onClick(View v){
                          Intent intent = new Intent("info.androidhive.navigationdrawer.activity.RegisterForContextMenuActivity");
                          startActivity(intent);
                      }
                  }
          );
      }
  
      /***
       * Load navigation menu header information
       * like background image, profile image
       * name, website, notifications action view (dot)
       */
      private void loadNavHeader() {
          // name, website
          txtName.setText("Ravi Tamada");
          txtWebsite.setText("www.androidhive.info");
  
          // loading header background image
          Glide.with(this).load(urlNavHeaderBg)
                  .crossFade()
                  .diskCacheStrategy(DiskCacheStrategy.ALL)
                  .into(imgNavHeaderBg);
  
          // Loading profile image
          Glide.with(this).load(urlProfileImg)
                  .crossFade()
                  .thumbnail(0.5f)
                  .bitmapTransform(new CircleTransform(this))
                  .diskCacheStrategy(DiskCacheStrategy.ALL)
                  .into(imgProfile);
      }
  
      /***
       * Returns respected fragment that user
       * selected from navigation menu
       */
      private void loadHomeFragment() {
          // selecting appropriate nav menu item
          selectNavMenu();
  
          // set toolbar title
          setToolbarTitle();
  
          // if user select the current navigation menu again, don't do anything
          // just close the navigation drawer
          if (getSupportFragmentManager().findFragmentByTag(CURRENT_TAG) != null) {
              drawer.closeDrawers();
  
              // show or hide the fab button
              toggleFab();
              return;
          }
  
          // Sometimes, when fragment has huge data, screen seems hanging
          // when switching between navigation menus
          // So using runnable, the fragment is loaded with cross fade effect
          // This effect can be seen in GMail app
          Runnable mPendingRunnable = new Runnable() {
              @Override
              public void run() {
                  // update the main content by replacing fragments
                  Fragment fragment = getHomeFragment();
                  FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
                  fragmentTransaction.setCustomAnimations(android.R.anim.fade_in,
                          android.R.anim.fade_out);
                  fragmentTransaction.replace(R.id.frame, fragment, CURRENT_TAG);
                  fragmentTransaction.commitAllowingStateLoss();
              }
          };
  
          // If mPendingRunnable is not null, then add to the message queue
          if (mPendingRunnable != null) {
              mHandler.post(mPendingRunnable);
          }
  
          // show or hide the fab button
          toggleFab();
  
          //Closing drawer on item click
          drawer.closeDrawers();
  
          // refresh toolbar menu
          invalidateOptionsMenu();
      }
  
      private Fragment getHomeFragment() {
          switch (navItemIndex) {
              case 0:
                  // home
                  PasswordsFragment passwordsFragment = new PasswordsFragment();
                  return passwordsFragment;
              case 1:
                  // photos
                  GenerarFragment generarFragment = new GenerarFragment();
                  return generarFragment;
              case 2:
                  // settings fragment
                  SettingsFragment settingsFragment = new SettingsFragment();
                  return settingsFragment;
              default:
                  return new PasswordsFragment();
          }
      }
  
      private void setToolbarTitle() {
          getSupportActionBar().setTitle(activityTitles[navItemIndex]);
      }
  
      private void selectNavMenu() {
          navigationView.getMenu().getItem(navItemIndex).setChecked(true);
      }
  
      private void setUpNavigationView() {
          //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu
          navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
  
              // This method will trigger on item Click of navigation menu
              @Override
              public boolean onNavigationItemSelected(MenuItem menuItem) {
  
                  //Check to see which item was being clicked and perform appropriate action
                  switch (menuItem.getItemId()) {
                      //Replacing the main content with ContentFragment Which is our Inbox View;
                      case R.id.home:
                          navItemIndex = 0;
                          CURRENT_TAG = TAG_HOME;
                          break;
                      case R.id.nav_photos:
                          navItemIndex = 1;
                          CURRENT_TAG = TAG_PHOTOS;
                          break;
                      case R.id.nav_settings:
                          navItemIndex = 2;
                          CURRENT_TAG = TAG_SETTINGS;
                          break;
                      case R.id.nav_about_us:
                          // launch new intent instead of loading fragment
                          startActivity(new Intent(MainActivity.this, AboutUsActivity.class));
                          drawer.closeDrawers();
                          return true;
                      case R.id.nav_privacy_policy:
                          // launch new intent instead of loading fragment
                          startActivity(new Intent(MainActivity.this, PrivacyPolicyActivity.class));
                          drawer.closeDrawers();
                          return true;
                      default:
                          navItemIndex = 0;
                  }
  
                  //Checking if the item is in checked state or not, if not make it in checked state
                  if (menuItem.isChecked()) {
                      menuItem.setChecked(false);
                  } else {
                      menuItem.setChecked(true);
                  }
                  menuItem.setChecked(true);
  
                  loadHomeFragment();
  
                  return true;
              }
          });
  
  
          ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.openDrawer, R.string.closeDrawer) {
  
              @Override
              public void onDrawerClosed(View drawerView) {
                  // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank
                  super.onDrawerClosed(drawerView);
              }
  
              @Override
              public void onDrawerOpened(View drawerView) {
                  // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank
                  super.onDrawerOpened(drawerView);
              }
          };
  
          //Setting the actionbarToggle to drawer layout
          drawer.setDrawerListener(actionBarDrawerToggle);
  
          //calling sync state is necessary or else your hamburger icon wont show up
          actionBarDrawerToggle.syncState();
      }
  
      @Override
      public void onBackPressed() {
          if (drawer.isDrawerOpen(GravityCompat.START)) {
              drawer.closeDrawers();
              return;
          }
  
          // This code loads home fragment when back key is pressed
          // when user is in other fragment than home
          if (shouldLoadHomeFragOnBackPress) {
              // checking if user is on other navigation menu
              // rather than home
              if (navItemIndex != 0) {
                  navItemIndex = 0;
                  CURRENT_TAG = TAG_HOME;
                  loadHomeFragment();
                  return;
              }
          }
  
          super.onBackPressed();
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
  
          // show menu only when home fragment is selected
          if (navItemIndex == 0) {
              getMenuInflater().inflate(R.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_logout) {
              Toast.makeText(getApplicationContext(), "Logout user!", Toast.LENGTH_LONG).show();
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
      // show or hide the fab
      private void toggleFab() {
          if (navItemIndex == 0)
              fab.show();
          else
              fab.hide();
      }
  }
  </code></pre>
  
  <p>This is the layout:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"
      tools:openDrawer="start"&gt;
  
      &lt;include
          layout="@layout/app_bar_main"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  
      &lt;android.support.design.widget.NavigationView
          android:id="@+id/nav_view"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          android:fitsSystemWindows="true"
          app:headerLayout="@layout/nav_header_main"
          app:menu="@menu/activity_main_drawer" /&gt;
  
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>This is AndroidManifest:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="info.androidhive.navigationdrawer"&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&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=".activity.MainActivity"
              android:label="@string/app_name"
              android:theme="@style/AppTheme.NoActionBar"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="info.androidhive.navigationdrawer.activity.RegisterForContextMenuActivity" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name=".activity.AboutUsActivity"
              android:label="@string/activity_title_about_us" /&gt;
          &lt;activity
              android:name=".activity.PrivacyPolicyActivity"
              android:label="@string/activity_title_privacy_policy" /&gt;
          &lt;activity android:name=".activity.RegisterForContextMenuActivity"&gt;&lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Style.xml:</p>
  
  <pre><code>    &lt;resources&gt;
  
      &lt;!-- Base application theme. --&gt;
      &lt;style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"&gt;
          &lt;!-- Customize your theme here. --&gt;
          &lt;item name="colorPrimary"&gt;@color/colorPrimary&lt;/item&gt;
          &lt;item name="colorPrimaryDark"&gt;@color/colorPrimaryDark&lt;/item&gt;
          &lt;item name="colorAccent"&gt;@color/colorAccent&lt;/item&gt;
      &lt;/style&gt;
      &lt;style name="AppTheme.NoActionBar"&gt;
          &lt;item name="windowActionBar"&gt;false&lt;/item&gt;
          &lt;item name="windowNoTitle"&gt;true&lt;/item&gt;
      &lt;/style&gt;
      &lt;style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /&gt;
      &lt;style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /&gt;
  
  &lt;/resources&gt;
  </code></pre>