title: Android Studio setSupportActionBar not working
body: <p>I'm trying to make full header app with Android Studio. I've MainActivity.java, navheader.xml, cardview.xml, activity_detail.xml. When i type the code, and build the code, no error found.</p>
  
  <p>When the app running, there are an error in MainActivity.java. </p>
  
  <p>The error said: </p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{id.wdharmana.doahindu/id.wdharmana.doahindu.MainActivity}: java.lang.NullPointerException
  </code></pre>
  
  <p>and</p>
  
  <pre><code>    at id.wdharmana.doahindu.MainActivity.onCreate(MainActivity.java:42)
  </code></pre>
  
  <p>This is my MainActivity.java:</p>
  
  <pre><code>     private CollapsingToolbarLayout ctb;
      private int mutedColor;
  
      private DrawerLayout drawerLayout;
      private NavigationView navigationView;
      private Snackbar snackbar;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          /* Top toolbar */
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
         /* Bottom toolbar. */
          Toolbar bottomToolbar = (Toolbar) findViewById(R.id.bottom_toolbar);
          bottomToolbar.inflateMenu(R.menu.menu_main);
          bottomToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
              @Override
              public boolean onMenuItemClick(MenuItem item) {
                  String message = null;
                  if (item.getItemId() == R.id.action_copy){
                      message = "Copy clicked";
                  }else if (item.getItemId() == R.id.action_cut){
                      message = "Cut clicked";
                  }else if (item.getItemId() == R.id.action_record){
                      message = "Record clicked";
                  }
  
                  Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
                  return true;
              }
          });
  
          RecyclerView recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
          recyclerView.setHasFixedSize(true);
          recyclerView.setLayoutManager(new LinearLayoutManager(this));
          // Add 8 cards
          MyAdapter adapter = new MyAdapter(new String[8]);
          recyclerView.setAdapter(adapter);
  
          ctb = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
  ///* Define the image */
  //        ImageView image = (ImageView) findViewById(R.id.image);
  ///* Decode bitmap from the image */
  //        Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
  //                R.drawable.full_image);
  ///* Generate palette from the image bitmap */
  //        Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
  //            @Override
  //            public void onGenerated(Palette palette) {
  //                    mutedColor = palette.getMutedColor
  //                            (ContextCompat.getColor(MainActivity.this,
  //                                    R.color.primary));
  //                      /* Set toolbar color from the palette */
  //                ctb.setContentScrimColor(mutedColor);
  //            }
  //        });
          ctb.setContentScrimColor(ContextCompat.getColor(MainActivity.this, R.color.primary));
          ctb.setTitle(getString(R.string.app_name));
  
          navigationView = (NavigationView) findViewById(R.id.nav_view);
          drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
  
          // On click of menu icon on toolbar
          toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
          toolbar.setNavigationOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  drawerLayout.openDrawer(GravityCompat.START);
              }
          });
  
  // On 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) {
                  // Set item in checked state
                  menuItem.setChecked(true);
  
  //TODO: handle navigation
  
  //Closing drawer on item click
                  drawerLayout.closeDrawers();
                  return true;
              }
          });
  
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Snackbar.make(v, "Do something awesome?",
                          Snackbar.LENGTH_LONG).show();
              }
          });
  
  
      }
  
      /* Create RecylcerView Adapter. */
      public static class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.ViewHolder&gt; {
          private String[] mDataset;
  
          public static class ViewHolder extends RecyclerView.ViewHolder {
              public View view;
              public TextView title;
              public ViewHolder(View v) {
                  super(v);
                  view = v;
                  title = (TextView) v.findViewById(R.id.card_title);
              }
          }
  
          public MyAdapter(String[] myDataset) {
              mDataset = myDataset;
          }
  
          @Override
          public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
              View cardview = LayoutInflater.from(parent.getContext())
                      .inflate(R.layout.cardview, parent, false);
              return new ViewHolder(cardview);
          }
  
          @Override
          public void onBindViewHolder(ViewHolder holder, int position) {
              holder.title.setText("Card " + (position + 1));
          }
  
          @Override
          public int getItemCount() {
              return mDataset.length;
          }
      }
  </code></pre>
  
  <p>Activity_detail.xml</p>
  
  <pre><code>&lt;android.support.v4.widget.DrawerLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:id="@+id/drawer"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true"&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"  tools:context=".MainActivity"&gt;
  
      &lt;android.support.design.widget.CoordinatorLayout
          android:id="@+id/main_content"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_alignParentTop="true"
          android:layout_marginBottom="?attr/actionBarSize"&gt;
  
          &lt;android.support.design.widget.AppBarLayout
              android:id="@+id/appbar"
              android:layout_width="match_parent"
              android:layout_height="192dp"&gt;
              &lt;android.support.design.widget.CollapsingToolbarLayout
                  android:id="@+id/collapsing_toolbar"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:theme="@style/ThemeOverlay.AppCompat.Dark"
                  app:layout_scrollFlags="scroll|exitUntilCollapsed"&gt;
                  &lt;ImageView
                      android:id="@+id/image"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:background="@drawable/full_image"
                      android:fitsSystemWindows="true"
                      android:scaleType="centerCrop"
                      app:layout_collapseMode="parallax" /&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_collapseMode="pin" /&gt;
              &lt;/android.support.design.widget.CollapsingToolbarLayout&gt;
          &lt;/android.support.design.widget.AppBarLayout&gt;
  
          &lt;android.support.v7.widget.RecyclerView
              android:id="@+id/my_recycler_view"
              android:scrollbars="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:paddingTop="8dp"
              android:paddingBottom="8dp"
              android:clipToPadding="false"
              app:layout_behavior="@string/appbar_scrolling_view_behavior"/&gt;
  
          &lt;android.support.design.widget.FloatingActionButton
              android:id="@+id/fab"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginBottom="16dp"
              android:layout_marginRight="16dp"
              android:layout_gravity="right|bottom"
              android:tint="@android:color/white"
              android:src="@drawable/ic_add"/&gt;
  
  
      &lt;/android.support.design.widget.CoordinatorLayout&gt;
  
      &lt;android.support.v7.widget.Toolbar
          android:id="@+id/bottom_toolbar"
          android:layout_height="?attr/actionBarSize"
          android:layout_width="match_parent"
          android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
          android:background="?attr/colorPrimaryDark"
          android:layout_alignParentBottom="true"/&gt;
  &lt;/RelativeLayout&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:background="#ffffff"
      android:clickable="true"
      app:headerLayout="@layout/navheader"
      app:menu="@menu/menu_navigation"
      app:itemBackground="?attr/selectableItemBackground"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>Card_View.xml</p>
  
  <pre><code>&lt;android.support.v7.widget.CardView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  xmlns:card_view="http://schemas.android.com/apk/res-auto"
  android:id="@+id/card_view"
  android:layout_gravity="center"
  android:layout_width="match_parent"
  android:layout_height="96dp"
  android:layout_marginLeft="16dp"
  android:layout_marginRight="16dp"
  android:layout_marginTop="8dp"
  android:layout_marginBottom="8dp"
  card_view:contentPadding="8dp"
  android:clickable="true"
  android:foreground="?attr/selectableItemBackground"&gt;
  &lt;TextView
      android:id="@+id/card_title"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:textAppearance="@style/TextAppearance.AppCompat.Title"
      tools:text="Title text"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>NavHeader.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="222dp"
  android:background="?attr/colorPrimaryDark"
  android:padding="16dp"
  android:orientation="vertical"&gt;
  </code></pre>
  
  <p></p>
  
  <p>Thanks for your attention and thanks in advance!</p>