title: Error inflating class android.support.design.widget.AppBarLayout
body: <p>I tried to create a game show the pictures and list of character name it. But when I run the app, it keeps crashing and show the error: </p>
  
  <blockquote>
    <p>Error inflating class android.support.design.widget.AppBarLayout.</p>
  </blockquote>
  
  <p>Here is the log:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                Process: com.example.user.celebguess, PID: 3166
                java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.celebguess/com.example.user.celebguess.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.widget.AppBarLayout
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                    at android.app.ActivityThread.-wrap11(Unknown Source:0)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                    at android.os.Handler.dispatchMessage(Handler.java:105)
                    at android.os.Looper.loop(Looper.java:164)
                    at android.app.ActivityThread.main(ActivityThread.java:6541)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                 Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.widget.AppBarLayout
                 Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.design.widget.AppBarLayout
                 Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.AppBarLayout" on path: DexPathList[[zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/base.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.user.celebguess-t-FEyHBoSS08L3kZz9tsZg==/lib/x86, /system/lib, /vendor/lib]]
                    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
                    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                    at android.view.LayoutInflater.createView(LayoutInflater.java:606)
                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
                    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
                    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.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                    at com.example.user.celebguess.MainActivity.onCreate(MainActivity.java:36)
                    at android.app.Activity.performCreate(Activity.java:6975)
                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
  E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                    at android.app.ActivityThread.-wrap11(Unknown Source:0)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                    at android.os.Handler.dispatchMessage(Handler.java:105)
                    at android.os.Looper.loop(Looper.java:164)
                    at android.app.ActivityThread.main(ActivityThread.java:6541)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
  </code></pre>
  
  <p>Here is the <code>activity_main.xml</code>: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout 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:orientation="vertical"
  tools:context="com.example.user.celebguess.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.v7.widget.Toolbar
          android:id="@+id/toolbar"
          android:layout_width="match_parent"
          android:layout_height="?attr/actionBarSize"
          android:background="?attr/colorPrimary"
          app:popupTheme="@style/AppTheme.PopupOverlay" /&gt;
  
  &lt;/android.support.design.widget.AppBarLayout&gt;
  
  &lt;include layout="@layout/content_main" /&gt;
  /&gt;
  </code></pre>
  
  <p></p>
  
  <p>Also here is the <code>styles.xml</code>:</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;
  </code></pre>
  
  <p></p>
  
  <p>Also here is the <code>main_activity.java</code> for the Java part:</p>
  
  <pre><code>import android.content.Intent;
  import android.content.SharedPreferences;
  import android.content.res.Configuration;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.widget.ArrayAdapter;
  import android.widget.GridView;
  import android.widget.ImageView;
  import android.widget.Toast;
  
  import java.util.ArrayList;
  import java.util.Map;
  
  public class MainActivity extends AppCompatActivity {
  
  private GridView gridView;
  private SharedPreferences preferences;
  private ArrayAdapter&lt;String&gt; names;
  private Toast currentToast;
  private ImageView img;
  private int numberOfChoice;
  private ArrayList&lt;String&gt; nameList;
  private ArrayList&lt;Integer&gt; photos;
  private ArrayList&lt;String&gt; nameForChoose;
  private Map&lt;String,Integer&gt; nameMap;
  private int currentPicNumber;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
  }
  
  @Override
  protected void onStart() {
      super.onStart();
  
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      int orientation = getResources().getConfiguration().orientation;
      if(orientation== Configuration.ORIENTATION_PORTRAIT) {
          getMenuInflater().inflate(R.menu.menu_main, menu);
      }
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      int id = item.getItemId();
  
  
      if (id == R.id.action_settings) {
          Intent intent = new Intent(this,Settings.class);
          startActivity(intent);
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  </code></pre>