title: java.lang.ClassCastException: android.support.design.widget.AppBarLayout cannot be cast to android.support.v7.widget.Toolbar
body: <p>I have no idea why i am getting this exception.</p>
  
  <p>Here is my code -</p>
  
  <p>toolbar.xml</p>
  
  <pre><code>&lt;android.support.design.widget.AppBarLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/appbar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"&gt;
  
      &lt;android.support.v7.widget.Toolbar
          android:id="@+id/toolbar"
          android:layout_width="match_parent"
          android:layout_height="?attr/actionBarSize"
          app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
          app:layout_scrollFlags="scroll|enterAlways" /&gt;
  &lt;/android.support.design.widget.AppBarLayout&gt;
  </code></pre>
  
  <p>I am including this layout in my xml file -</p>
  
  <pre><code>  &lt;include android:id="@+id/photoGalleryToolbar"
          layout="@layout/toolbar"/&gt;
  </code></pre>
  
  <p>And then i am using following code in my activity - </p>
  
  <pre><code>Toolbar toolbar = (Toolbar) findViewById(R.id.photoGalleryToolbar);
          setSupportActionBar(toolbar);
          final android.support.v7.app.ActionBar actionBar = getSupportActionBar();
          if (actionBar != null) {
              actionBar.setHomeAsUpIndicator(R.drawable.ic_keyboard_backspace_white_24dp);
              actionBar.setDisplayShowTitleEnabled(true);
              actionBar.setTitle("Kidster Photo Gallery");
              actionBar.setDisplayHomeAsUpEnabled(true);
          }
  </code></pre>
  
  <p>The exception is coming at following line - </p>
  
  <pre><code>Toolbar toolbar = (Toolbar) findViewById(R.id.photoGalleryToolbar);
  </code></pre>
  
  <p>I had checked the imports and they all are right and i am using support library.</p>