title: Android java, Side drawer menu is showing up whenever the app is launched and the app is getting crashed on closing the menu
body: <p>java.lang.IllegalArgumentException: No drawer view found with gravity LEFT</p>
  <p>at com.example.books.MainActivity.onOptionsItemSelected(MainActivity.java:245)</p>
  <p>The terminal shows that the error is with the onOptionsItemSelected function</p>
  <p>I have referred many StackOverflow posts regarding errors with side navigation drawer but I couldn't find the solution</p>
  <p>Logcat</p>
  <pre><code> 2022-05-08 17:13:15.175 867-867/com.example.books E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.books, PID: 867
  java.lang.IllegalArgumentException: No drawer view found with gravity LEFT
      at androidx.drawerlayout.widget.DrawerLayout.openDrawer(DrawerLayout.java:1736)
      at androidx.drawerlayout.widget.DrawerLayout.openDrawer(DrawerLayout.java:1722)
      at androidx.appcompat.app.ActionBarDrawerToggle.toggle(ActionBarDrawerToggle.java:287)
      androidx.appcompat.app.ActionBarDrawerToggle.onOptionsItemSelected(MainActivity.java:245)
      at com.example.books.MainActivity.onOptionsItemSelected(MainActivity.java:245)
      at android.app.Activity.onMenuItemSelected(Activity.java:4324)
      at androidx.fragment.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:352)
      at androidx.appcompat.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:264)
      at androidx.appcompat.view.WindowCallbackWrapper.onMenuItemSelected
      at androidx.appcompat.widget.ToolbarWidgetWrapper$1.onClick(ToolbarWidgetWrapper.java:188)
      at android.view.View.performClick(View.java:8160)
      at android.view.View.performClickInternal(View.java:8137)
      at android.view.View.access$3700(View.java:888)
      at android.view.View$PerformClick.run(View.java:30250)
      at android.os.Handler.handleCallback(Handler.java:938)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:246)
      at android.app.ActivityThread.main(ActivityThread.java:8443)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
  </code></pre>
  <p>activity_main.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  
  &lt;androidx.drawerlayout.widget.DrawerLayout
  
  
  xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  android:layout_gravity=&quot;left&quot;
  android:layout_width=&quot;match_parent&quot;
  android:layout_height=&quot;match_parent&quot;
  android:orientation=&quot;vertical&quot;
  android:id=&quot;@+id/dl&quot;&gt;
  
  &lt;androidx.constraintlayout.widget.ConstraintLayout
  
  android:layout_width=&quot;match_parent&quot;
  android:layout_height=&quot;match_parent&quot;
  tools:context=&quot;.MainActivity&quot;&gt;
  
  &lt;SearchView
      android:id=&quot;@+id/searchView&quot;
      android:layout_width=&quot;277dp&quot;
      android:layout_height=&quot;34dp&quot;
      android:layout_alignParentTop=&quot;true&quot;
      android:background=&quot;@drawable/bg_white_rounded&quot;
      android:iconifiedByDefault=&quot;false&quot;
      android:queryHint=&quot;Search book,title,author, etc..&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintEnd_toEndOf=&quot;parent&quot;
      app:layout_constraintHorizontal_bias=&quot;0.119&quot;
      app:layout_constraintStart_toStartOf=&quot;parent&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;
      app:layout_constraintVertical_bias=&quot;0.035&quot;
      app:queryBackground=&quot;@drawable/bg_white_rounded&quot;
      app:submitBackground=&quot;@drawable/bg_white_rounded&quot;
      tools:ignore=&quot;MissingConstraints&quot;&gt;
  
  &lt;/SearchView&gt;
  
  &lt;androidx.cardview.widget.CardView
      android:id=&quot;@+id/cardView2&quot;
      android:layout_width=&quot;96dp&quot;
      android:layout_height=&quot;100dp&quot;
      app:cardCornerRadius=&quot;8dp&quot;
      app:cardElevation=&quot;8dp&quot;
      app:cardMaxElevation=&quot;10dp&quot;
      app:contentPadding=&quot;@dimen/cardview_default_elevation&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintEnd_toEndOf=&quot;parent&quot;
      app:layout_constraintStart_toStartOf=&quot;parent&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;
      app:layout_constraintVertical_bias=&quot;0.131&quot;&gt;
  
      &lt;ImageView
          android:id=&quot;@+id/idIVCourseImage5&quot;
          android:layout_marginLeft=&quot;10dp&quot;
          android:layout_width=&quot;76dp&quot;
          android:layout_height=&quot;100dp&quot;
          android:src=&quot;@drawable/bookdonation&quot; /&gt;
  
  &lt;/androidx.cardview.widget.CardView&gt;
  
  
  &lt;androidx.cardview.widget.CardView
      android:id=&quot;@+id/cardView&quot;
      android:layout_width=&quot;96dp&quot;
      android:layout_height=&quot;100dp&quot;
      app:cardCornerRadius=&quot;8dp&quot;
      app:cardElevation=&quot;8dp&quot;
      app:cardMaxElevation=&quot;10dp&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintEnd_toEndOf=&quot;parent&quot;
      app:layout_constraintHorizontal_bias=&quot;0.136&quot;
      app:layout_constraintStart_toStartOf=&quot;parent&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;
      app:layout_constraintVertical_bias=&quot;0.131&quot;&gt;
  
      &lt;ImageView
          android:id=&quot;@+id/idIVCourseImage1&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          android:layout_marginLeft=&quot;0dp&quot;
          android:clickable=&quot;true&quot;
          android:src=&quot;@drawable/onlinepurchase&quot; /&gt;
  &lt;/androidx.cardview.widget.CardView&gt;
  
  
  &lt;androidx.cardview.widget.CardView
      android:id=&quot;@+id/cardView3&quot;
      android:layout_width=&quot;96dp&quot;
      android:layout_height=&quot;100dp&quot;
      app:cardCornerRadius=&quot;8dp&quot;
      app:cardElevation=&quot;8dp&quot;
      app:cardMaxElevation=&quot;10dp&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintEnd_toEndOf=&quot;parent&quot;
      app:layout_constraintHorizontal_bias=&quot;0.865&quot;
      app:layout_constraintStart_toStartOf=&quot;parent&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;
      app:layout_constraintVertical_bias=&quot;0.131&quot; &gt;
      &lt;ImageView
          android:id=&quot;@+id/idIVCourseImage2&quot;
          android:layout_marginTop=&quot;10dp&quot;
          android:layout_width=&quot;96dp&quot;
          android:layout_height=&quot;80dp&quot;
          android:src=&quot;@drawable/prouddonars&quot; /&gt;
  &lt;/androidx.cardview.widget.CardView&gt;
  
  
  &lt;TextView
      android:id=&quot;@+id/textView7&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:text=&quot;FICTION AND NON-FICTION BOOKS&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintEnd_toEndOf=&quot;parent&quot;
      app:layout_constraintHorizontal_bias=&quot;0.115&quot;
      app:layout_constraintStart_toStartOf=&quot;parent&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;
      app:layout_constraintVertical_bias=&quot;0.519&quot; /&gt;
  
  &lt;androidx.recyclerview.widget.RecyclerView
      android:id=&quot;@+id/idRVCourse&quot;
      android:layout_width=&quot;403dp&quot;
      android:layout_height=&quot;333dp&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintEnd_toEndOf=&quot;parent&quot;
      app:layout_constraintHorizontal_bias=&quot;1.0&quot;
      app:layout_constraintStart_toStartOf=&quot;parent&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;
      app:layout_constraintVertical_bias=&quot;0.961&quot;
      tools:ignore=&quot;MissingConstraints&quot;&gt;
  
  &lt;/androidx.recyclerview.widget.RecyclerView&gt;
  
  &lt;TextView
      android:id=&quot;@+id/textView9&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:fontFamily=&quot;@font/inter_medium&quot;
      android:text=&quot;Purchase books&quot;
      android:textSize=&quot;12sp&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintEnd_toEndOf=&quot;parent&quot;
      app:layout_constraintHorizontal_bias=&quot;0.122&quot;
      app:layout_constraintStart_toStartOf=&quot;parent&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;
      app:layout_constraintVertical_bias=&quot;0.276&quot; /&gt;
  
  &lt;TextView
      android:id=&quot;@+id/textView10&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:fontFamily=&quot;@font/inter_medium&quot;
      android:text=&quot;Donate books&quot;
      android:textSize=&quot;12sp&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintEnd_toEndOf=&quot;parent&quot;
      app:layout_constraintHorizontal_bias=&quot;0.498&quot;
      app:layout_constraintStart_toStartOf=&quot;parent&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;
      app:layout_constraintVertical_bias=&quot;0.276&quot;
      android:clickable=&quot;true&quot;/&gt;
  
  &lt;TextView
      android:id=&quot;@+id/textView11&quot;
      android:layout_width=&quot;89dp&quot;
      android:layout_height=&quot;17dp&quot;
      android:fontFamily=&quot;@font/inter_medium&quot;
      android:text=&quot;Proud donars&quot;
      android:textSize=&quot;12sp&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintEnd_toEndOf=&quot;parent&quot;
      app:layout_constraintHorizontal_bias=&quot;0.869&quot;
      app:layout_constraintStart_toStartOf=&quot;parent&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;
      app:layout_constraintVertical_bias=&quot;0.275&quot; /&gt;
  
  
  &lt;LinearLayout
      android:id=&quot;@+id/linearLayout&quot;
      android:layout_width=&quot;match_parent&quot;
      android:orientation=&quot;horizontal&quot;
      android:layout_height=&quot;wrap_content&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;
  
  &lt;/LinearLayout&gt;
  
  &lt;HorizontalScrollView
      android:id=&quot;@+id/horizontalScrollView&quot;
      android:layout_width=&quot;407dp&quot;
      android:layout_height=&quot;148dp&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintEnd_toEndOf=&quot;parent&quot;
      app:layout_constraintHorizontal_bias=&quot;1.0&quot;
      app:layout_constraintStart_toStartOf=&quot;parent&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;
      app:layout_constraintVertical_bias=&quot;0.401&quot;
      tools:ignore=&quot;MissingConstraints&quot;&gt;
  
      &lt;LinearLayout
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;120dp&quot;
          android:orientation=&quot;horizontal&quot;&gt;
  
  
      &lt;androidx.cardview.widget.CardView
              android:layout_width=&quot;408dp&quot;
              android:layout_height=&quot;136dp&quot;
              android:elevation=&quot;10dp&quot;
              app:cardCornerRadius=&quot;8dp&quot;
              app:cardMaxElevation=&quot;10dp&quot;
              app:cardPreventCornerOverlap=&quot;true&quot;
              app:cardUseCompatPadding=&quot;true&quot;&gt;
  
              &lt;ImageView
                  android:layout_width=&quot;99dp&quot;
                  android:layout_height=&quot;99dp&quot;
                  android:src=&quot;@drawable/medical&quot;&gt;&lt;/ImageView&gt;
  
              &lt;TextView
                  android:layout_width=&quot;210dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginLeft=&quot;110dp&quot;
                  android:layout_marginTop=&quot;15dp&quot;
                  android:text=&quot;MEDICAL HEALTH AND SCIENCE BOOKS&quot;&gt;&lt;/TextView&gt;
  
              &lt;TextView
                  android:layout_width=&quot;200dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginLeft=&quot;110dp&quot;
                  android:layout_marginTop=&quot;50dp&quot;
  
                  android:text=&quot;Biochemistry| Physiotherapy | Phathalogy&quot;&gt;&lt;/TextView&gt;
  
  
              &lt;Button
                  android:id=&quot;@+id/buttonmed&quot;
                  android:layout_width=&quot;68dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_gravity=&quot;right&quot;
                  android:layout_marginTop=&quot;55dp&quot;
                  android:layout_marginRight=&quot;10dp&quot;
                  android:fontFamily=&quot;@font/inter&quot;
                  android:text=&quot;Order &quot;
                  android:textAllCaps=&quot;false&quot;
                  android:textSize=&quot;10sp&quot; /&gt;
  
  
          &lt;/androidx.cardview.widget.CardView&gt;
  
          &lt;androidx.cardview.widget.CardView
              android:layout_width=&quot;408dp&quot;
              android:layout_height=&quot;136dp&quot;
              android:layout_marginBottom=&quot;10dp&quot;
              android:elevation=&quot;10dp&quot;
              app:cardCornerRadius=&quot;8dp&quot;
              app:cardMaxElevation=&quot;10dp&quot;
              app:cardPreventCornerOverlap=&quot;true&quot;
              app:cardUseCompatPadding=&quot;true&quot;&gt;
  
              &lt;ImageView
                  android:layout_width=&quot;96dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:src=&quot;@drawable/fictionandnonfiction&quot;&gt;&lt;/ImageView&gt;
  
              &lt;TextView
                  android:layout_width=&quot;210dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginLeft=&quot;110dp&quot;
                  android:layout_marginTop=&quot;15dp&quot;
                  android:text=&quot;EXPLORE THE WIDE RANGE OF FICTION AND NON FICTION&quot;&gt;&lt;/TextView&gt;
  
              &lt;TextView
                  android:layout_width=&quot;200dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginLeft=&quot;110dp&quot;
                  android:layout_marginTop=&quot;50dp&quot;
                  android:text=&quot;Science Fiction| Short stories | Teens&quot;&gt;&lt;/TextView&gt;
  
  
              &lt;Button
                  android:id=&quot;@+id/buttoneng&quot;
                  android:layout_width=&quot;68dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_gravity=&quot;right&quot;
                  android:layout_marginTop=&quot;55dp&quot;
                  android:layout_marginRight=&quot;10dp&quot;
                  android:fontFamily=&quot;@font/inter&quot;
                  android:text=&quot;Order&quot;
                  android:textAllCaps=&quot;false&quot;
                  android:textSize=&quot;10sp&quot; /&gt;
  
  
          &lt;/androidx.cardview.widget.CardView&gt;
  
  
          &lt;androidx.cardview.widget.CardView
              android:layout_width=&quot;408dp&quot;
              android:layout_height=&quot;136dp&quot;
              android:elevation=&quot;10dp&quot;
              app:cardCornerRadius=&quot;8dp&quot;
              app:cardMaxElevation=&quot;10dp&quot;
              app:cardPreventCornerOverlap=&quot;true&quot;
              app:cardUseCompatPadding=&quot;true&quot;&gt;
  
              &lt;ImageView
                  android:layout_width=&quot;96dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:src=&quot;@drawable/ncert&quot;&gt;&lt;/ImageView&gt;
  
              &lt;TextView
                  android:layout_width=&quot;210dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginLeft=&quot;110dp&quot;
                  android:layout_marginTop=&quot;15dp&quot;
                  android:text=&quot;NCERT BOOKS FOR CLASS 1-12&quot;&gt;&lt;/TextView&gt;
  
              &lt;TextView
                  android:layout_width=&quot;200dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginLeft=&quot;110dp&quot;
                  android:layout_marginTop=&quot;50dp&quot;
                  android:text=&quot;Physics| Chemistry | Mathematics&quot;&gt;&lt;/TextView&gt;
  
              &lt;Button
                  android:id=&quot;@+id/buttonfiction&quot;
                  android:layout_width=&quot;68dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_gravity=&quot;right&quot;
                  android:layout_marginTop=&quot;55dp&quot;
                  android:layout_marginRight=&quot;10dp&quot;
                  android:fontFamily=&quot;@font/inter&quot;
                  android:text=&quot;Order&quot;
                  android:textAllCaps=&quot;false&quot;
                  android:textSize=&quot;10sp&quot; /&gt;
  
  
          &lt;/androidx.cardview.widget.CardView&gt;
  
          &lt;androidx.cardview.widget.CardView
              android:layout_width=&quot;408dp&quot;
              android:layout_height=&quot;136dp&quot;
              android:elevation=&quot;10dp&quot;
              app:cardCornerRadius=&quot;8dp&quot;
              app:cardMaxElevation=&quot;10dp&quot;
              app:cardPreventCornerOverlap=&quot;true&quot;
              app:cardUseCompatPadding=&quot;true&quot;&gt;
  
              &lt;ImageView
                  android:layout_width=&quot;96dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:src=&quot;@drawable/competative&quot;&gt;&lt;/ImageView&gt;
  
              &lt;TextView
                  android:layout_width=&quot;210dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginLeft=&quot;110dp&quot;
                  android:layout_marginTop=&quot;15dp&quot;
                  android:text=&quot; WIDE RANGE OF AVAILABLE COMPITATIVE EXAM BOOKS&quot;&gt;&lt;/TextView&gt;
  
              &lt;TextView
                  android:layout_width=&quot;200dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginLeft=&quot;110dp&quot;
                  android:layout_marginTop=&quot;50dp&quot;
                  android:text=&quot;Banking| UPSC| SSC&quot;&gt;&lt;/TextView&gt;
  
              &lt;Button
                  android:id=&quot;@+id/buttonfinance&quot;
                  android:layout_width=&quot;77dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_gravity=&quot;right&quot;
                  android:layout_marginTop=&quot;55dp&quot;
                  android:layout_marginRight=&quot;10dp&quot;
                  android:fontFamily=&quot;@font/inter&quot;
                  android:text=&quot;Order&quot;
                  android:textAllCaps=&quot;false&quot;
                  android:textSize=&quot;10sp&quot; /&gt;
  
  
          &lt;/androidx.cardview.widget.CardView&gt;
      &lt;/LinearLayout&gt;
  &lt;/HorizontalScrollView&gt;
  
  &lt;ImageView
      android:id=&quot;@+id/imageView5&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:clickable=&quot;true&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintEnd_toEndOf=&quot;parent&quot;
      app:layout_constraintHorizontal_bias=&quot;0.777&quot;
      app:layout_constraintStart_toStartOf=&quot;parent&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;
      app:layout_constraintVertical_bias=&quot;0.048&quot;
      app:srcCompat=&quot;@drawable/ic_favorite&quot; /&gt;
  
  &lt;ImageView
      android:id=&quot;@+id/imageView7&quot;
      android:layout_width=&quot;36dp&quot;
      android:layout_height=&quot;29dp&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintEnd_toEndOf=&quot;parent&quot;
      app:layout_constraintHorizontal_bias=&quot;1.0&quot;
      app:layout_constraintStart_toStartOf=&quot;parent&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;
      app:layout_constraintVertical_bias=&quot;0.045&quot;
      app:srcCompat=&quot;@drawable/cart1&quot; /&gt;
  
  &lt;ImageView
      android:id=&quot;@+id/imageView8&quot;
      android:layout_width=&quot;32dp&quot;
      android:layout_height=&quot;27dp&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintEnd_toEndOf=&quot;@+id/linearLayout&quot;
      app:layout_constraintHorizontal_bias=&quot;0.889&quot;
      app:layout_constraintStart_toStartOf=&quot;@+id/linearLayout&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;
      app:layout_constraintVertical_bias=&quot;0.048&quot;
      app:srcCompat=&quot;@drawable/ic_location&quot; /&gt;
  
  
     &lt;com.google.android.material.navigation.NavigationView
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;match_parent&quot;
    android:id=&quot;@+id/idnav_bar&quot;
    android:layout_gravity=&quot;left&quot;
    android:fitsSystemWindows=&quot;true&quot;
    app:headerLayout=&quot;@layout/nav_header&quot;
    app:menu=&quot;@menu/drawer_menu&quot;
    tools:ignore=&quot;InvalidId,MissingConstraints&quot; /&gt;
    &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
    &lt;/androidx.drawerlayout.widget.DrawerLayout&gt;
  </code></pre>
  <p>Mainactivity.java</p>
  <pre><code>  package com.example.books;
  
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Gravity;
    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 androidx.appcompat.widget.Toolbar;
  
    import com.google.android.material.navigation.NavigationView;
    import com.synnapps.carouselview.CarouselView;
    import com.synnapps.carouselview.ImageClickListener;
    import com.synnapps.carouselview.ImageListener;
  
    import androidx.annotation.NonNull;
    import androidx.appcompat.app.ActionBar;
    import androidx.appcompat.app.ActionBarDrawerToggle;
    import androidx.appcompat.app.AppCompatActivity;
    import androidx.core.view.GravityCompat;
    import androidx.drawerlayout.widget.DrawerLayout;
    import androidx.recyclerview.widget.DefaultItemAnimator;
    import androidx.recyclerview.widget.LinearLayoutManager;
    import androidx.recyclerview.widget.RecyclerView;
    import java.util.ArrayList;
    import android.view.MenuItem.OnMenuItemClickListener;
    import java.util.Objects;
  
  
  
    import org.w3c.dom.Text;
  
  
  
    public class MainActivity extends AppCompatActivity {
     private Button button;
     private Button medbutton;
     private RecyclerView courseRV;
     public DrawerLayout dl;
     private Toolbar toolbar;
     public ActionBarDrawerToggle abdt;
     public TextView TVdonars;
     public TextView TVdonatebooks;
     public TextView TVpurchasebooks;
     public ImageView wishlistimg;
  
  
  
     private ArrayList&lt;CourseModel&gt; courseModelArrayList;
  
  
  
  
      private int[] mImages = new int[]{
          R.drawable.academic, R.drawable.engineering, R.drawable.medical, R.drawable.fiction
  
      };
      private String[] mImagesTitle = new String[]{
          &quot;Academic&quot;, &quot;Engineering&quot;, &quot;Medical&quot;, &quot;Fiction&quot;
      };
  
  
  
     @Override
     protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      getSupportActionBar().setTitle(&quot;Classic Books Donar&quot;);
      medbutton = findViewById(R.id.buttonmed);
      wishlistimg = findViewById(R.id.imageView5);
      //button = (Button) findViewById(R.id.button2);
      courseRV = findViewById(R.id.idRVCourse);
      TVpurchasebooks = findViewById(R.id.textView9);
      TVdonatebooks = findViewById(R.id.textView10);
      TVdonars = findViewById(R.id.textView11);
  
  
      TVdonatebooks.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent intent = new Intent(MainActivity.this, Register.class);
              startActivity(intent);
          }
  
      });
      TVdonars.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent intent = new Intent(MainActivity.this, Prouddonars.class);
              startActivity(intent);
          }
  
      });
  
      TVpurchasebooks.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent intent = new Intent(MainActivity.this, Purchasebooks.class);
              startActivity(intent);
          }
  
      });
      final NavigationView nav_view = (NavigationView) findViewById(R.id.idnav_bar);
      nav_view.setNavigationItemSelectedListener(new 
      NavigationView.OnNavigationItemSelectedListener() {
  
          @Override
          public boolean onNavigationItemSelected(@NonNull MenuItem item) {
              int id = item.getItemId();
              if (id == R.id.select_catogery) {
                  Toast.makeText(MainActivity.this, &quot;Select Catogery&quot;, 
          Toast.LENGTH_SHORT).show();
              }
  
  
              if (id == R.id.engineering) {
                  Toast.makeText(MainActivity.this, &quot;Engineering&quot;, Toast.LENGTH_SHORT).show();
              }
              if (id == R.id.medical) {
                  Toast.makeText(MainActivity.this, &quot;Medical&quot;, Toast.LENGTH_SHORT).show();
              }
              return true;
          }
         });
  
  
  
  
      dl = (DrawerLayout) findViewById(R.id.dl);
      abdt = new ActionBarDrawerToggle(this, dl, toolbar, R.string.open, R.string.close);
      abdt.setDrawerIndicatorEnabled(true);
  
      //Toolbar toolbar = findViewById(R.id.toolbar);
      //setSupportActionBar(toolbar);
  
      dl.addDrawerListener(abdt);
      abdt.syncState();
  
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
  
   
  
      courseModelArrayList = new ArrayList&lt;&gt;();
      courseModelArrayList.add(new CourseModel(&quot;Design of Machine Elements, Fourth Edition&quot;, &quot;V 
      B Bhandari&quot;, R.drawable.designofmachineelements));
      courseModelArrayList.add(new CourseModel(&quot;Fluid Mechanics, Sixth Edition&quot;, &quot;Munsun, 
      Okilshi,Huebsch &amp; Rothmayer&quot;, R.drawable.fluidmechanics));
      courseModelArrayList.add(new CourseModel(&quot;Fundamentals of Thermodynamics&quot;, &quot;Claus 
      Borgnakke &amp; Richard E Sonntag&quot;, R.drawable.thermodynamics));
      courseModelArrayList.add(new CourseModel(&quot;Shigley's Mechanical Engineering Design&quot;, 
      &quot;Richard G Budynas &amp; JJ Keith Nisbett&quot;, R.drawable.mechanicalengineeringdesign));
      courseModelArrayList.add(new CourseModel(&quot;Atlas of Human Anatomy, Seventh Edition&quot;, &quot;Frank 
      H. Netter, MD &quot;, R.drawable.atlasofhumananatomy));
      courseModelArrayList.add(new CourseModel(&quot;Data structures and algorithms&quot;, &quot; Alfred V.Aho, 
      John E.Hopcroft, Jeffrey D.Ullman&quot;, R.drawable.datastructures));
      courseModelArrayList.add(new CourseModel(&quot;Textbook of Clinical Neuroanatomy, Third 
      Edition&quot;, &quot;Vishram Singh &quot;, R.drawable.clinicalneuroanatomy));
  
      // we are initializing our adapter class and passing our arraylist to it.
      CourseAdapter courseAdapter = new CourseAdapter(this, courseModelArrayList);
  
      // below line is for setting a layout manager for our recycler view.
      // here we are creating vertical list so we will provide orientation as vertical
      LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, 
      LinearLayoutManager.VERTICAL, false);
  
      // in below two lines we are setting layoutmanager and adapter to our recycler view.
      courseRV.setLayoutManager(linearLayoutManager);
      courseRV.setAdapter(courseAdapter);
  
  
      medbutton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent intent = new Intent(MainActivity.this, Medical.class);
              startActivity(intent);
          }
      });
  
      wishlistimg.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent intent = new Intent(MainActivity.this, Wishlist.class);
              startActivity(intent);
          }
      });
  
      
  
     @Override
     public boolean onOptionsItemSelected(MenuItem item){
     int id = item.getItemId();
     if (abdt.onOptionsItemSelected(item)) {
         return true;
     }
     return super.onOptionsItemSelected(item);
    }
    }
  </code></pre>