title: IllegalArgumentException: ID does not reference a View inside this Activity
body: <p>I have been trying to make a home page for my app which contains some modern dashboard along with navigation drawer.
  Error found in my code:</p>
  
  <pre><code> E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.thinkerlab, PID: 13956
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.thinkerlab/com.example.thinkerlab.HomePage}: java.lang.IllegalArgumentException: ID does not reference a View inside this Activity
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2517)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2577)
          at android.app.ActivityThread.access$1000(ActivityThread.java:166)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1414)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:148)
          at android.app.ActivityThread.main(ActivityThread.java:5619)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737)
       Caused by: java.lang.IllegalArgumentException: ID does not reference a View inside this Activity
          at androidx.core.app.ActivityCompat.requireViewById(ActivityCompat.java:368)
          at androidx.navigation.Navigation.findNavController(Navigation.java:58)
          at com.example.thinkerlab.HomePage.onCreate(HomePage.java:70)
          at android.app.Activity.performCreate(Activity.java:6351)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2470)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2577) 
          at android.app.ActivityThread.access$1000(ActivityThread.java:166) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1414) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:148) 
          at android.app.ActivityThread.main(ActivityThread.java:5619) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737) 
  </code></pre>
  
  <p>AndroidManifest.xml file of my project:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity android:name=".Page1"&gt;&lt;/activity&gt;
      &lt;activity android:name=".Startpage" /&gt;
      &lt;activity
          android:name=".HomePage"
          android:label="@string/title_activity_home_page"
          android:theme="@style/AppTheme.NoActionBar" /&gt;
      &lt;activity android:name=".ResetPassword" /&gt;
      &lt;activity android:name=".RegistrationActivity" /&gt;
      &lt;activity android:name=".MainActivity"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;meta-data
          android:name="preloaded_fonts"
          android:resource="@array/preloaded_fonts" /&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>HomePage.java file of my project:</p>
  
  <pre><code> package com.example.thinkerlab;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Build;
  import android.os.Bundle;
  import android.view.MenuItem;
  import android.view.Menu;
  import android.widget.Toast;
  
  import com.google.android.material.navigation.NavigationView;
  
  import androidx.annotation.NonNull;
  import androidx.annotation.RequiresApi;
  import androidx.appcompat.app.ActionBar;
  import androidx.appcompat.app.ActionBarDrawerToggle;
  import androidx.core.view.GravityCompat;
  import androidx.navigation.NavController;
  import androidx.navigation.Navigation;
  import androidx.navigation.ui.AppBarConfiguration;
  import androidx.navigation.ui.NavigationUI;
  import androidx.drawerlayout.widget.DrawerLayout;
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.appcompat.widget.Toolbar;
  
  public class HomePage extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
  
      DrawerLayout drawerLayout;
      NavigationView navigationView;
      Toolbar toolbar;
      ActionBar actionBar;
      Activity activity;
  
      private AppBarConfiguration mAppBarConfiguration;
  
      @RequiresApi(api = Build.VERSION_CODES.KITKAT)
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_home_page);
          toolbar = findViewById(R.id.toolbar2);
          setSupportActionBar(toolbar);
  
         actionBar = getSupportActionBar();
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
          getSupportActionBar().setHomeButtonEnabled(true);
  
          drawerLayout = findViewById(R.id.drawer_layout);
          navigationView = findViewById(R.id.nav_view);
  
          Menu menu=navigationView.getMenu();
          menu.findItem(R.id.nav_Log_out).setVisible(true);
          menu.findItem(R.id.nav_Profile).setVisible(true);
          navigationView.bringToFront();
  
          ActionBarDrawerToggle toggle= new ActionBarDrawerToggle(this,drawerLayout,toolbar,R.string.navigation_drawer_open,R.string.navigation_drawer_close);
          drawerLayout.addDrawerListener(toggle);
          toggle.syncState();
          navigationView.setNavigationItemSelectedListener(this);
          navigationView.setCheckedItem(R.id.nav_home);
  
  
          // Passing each menu ID as a set of Ids because each
          // menu should be considered as top level destinations.
          mAppBarConfiguration = new AppBarConfiguration.Builder(
                  R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow)
                  .setDrawerLayout(drawerLayout)
                  .build();
          NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
          NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
          NavigationUI.setupWithNavController(navigationView, navController);
      }
  
  
  
  
      public void onBackPressed()
      {
          if(drawerLayout.isDrawerOpen(GravityCompat.START))
          {
              drawerLayout.closeDrawer(GravityCompat.START);
          }
          else
          {
              super.onBackPressed();
          }
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.home_page, menu);
          return true;
      }
  
  
  
      @Override
      public boolean onSupportNavigateUp() {
          NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
          return NavigationUI.navigateUp(navController, mAppBarConfiguration)
                  || super.onSupportNavigateUp();
      }
  
  
      @Override
      public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  
          switch (item.getItemId())
          {
              case R.id.nav_home:
                  break;
              case R.id.nav_Science:
                  startActivity(new Intent(HomePage.this,Page1.class));
                  break;
              case R.id.nav_Contact_Us:
                  Toast.makeText(this,"Share",Toast.LENGTH_SHORT).show();
                  break;
              case R.id.nav_Log_out:
                  startActivity(new Intent(HomePage.this,MainActivity.class));
                  break;
  
          }
          drawerLayout.closeDrawer(GravityCompat.START);
          return  true;
      }
  }
  </code></pre>
  
  <p>styles.xml file of my project:</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>My activity_home_page xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;androidx.drawerlayout.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;com.google.android.material.navigation.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/header"
          app:menu="@menu/main_menu" /&gt;
  
      &lt;ScrollView
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
  
  
          &lt;androidx.constraintlayout.widget.ConstraintLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"&gt;
  
  
              &lt;ImageView
                  android:id="@+id/iv1"
                  android:layout_width="0dp"
                  android:layout_height="150dp"
                  android:layout_marginEnd="16dp"
                  android:layout_marginRight="16dp"
                  app:layout_constraintEnd_toEndOf="parent"
                  app:layout_constraintStart_toEndOf="@+id/textView2"
                  app:layout_constraintTop_toBottomOf="@+id/toolbar2"
                  app:srcCompat="@drawable/p" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView3"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_marginStart="16dp"
                  android:layout_marginLeft="16dp"
                  android:fontFamily="sans-serif-condensed-medium"
                  android:text="Let's Think and Build"
                  android:textSize="18sp"
                  app:layout_constraintEnd_toStartOf="@+id/iv1"
                  app:layout_constraintHorizontal_bias="0.0"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintTop_toBottomOf="@+id/textView2" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginStart="16dp"
                  android:layout_marginLeft="16dp"
                  android:fontFamily="serif"
                  android:text="Thinker Lab"
                  android:textSize="36sp"
                  app:layout_constraintEnd_toStartOf="@+id/iv1"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintTop_toBottomOf="@+id/toolbar2" /&gt;
              &lt;androidx.appcompat.widget.Toolbar
                  android:id="@+id/toolbar2"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:background="#04FFFFFF"
                  app:layout_constraintEnd_toEndOf="parent"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintTop_toTopOf="parent"
  
  
                  android:minHeight="?attr/actionBarSize"
                  android:theme="?attr/actionBarTheme"
                  tools:layout_editor_absoluteX="1dp"
                  tools:ignore="MissingConstraints" /&gt;
  
  
              &lt;LinearLayout
                  android:id="@+id/linearLayout2"
                  android:layout_width="0dp"
                  android:layout_height="175dp"
                  android:orientation="horizontal"
                  android:padding="10dp"
                  app:layout_constraintEnd_toEndOf="parent"
                  app:layout_constraintHorizontal_bias="0.0"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintTop_toBottomOf="@+id/iv1"&gt;
  
                  &lt;androidx.cardview.widget.CardView
                      android:layout_width="0dp"
                      android:layout_height="match_parent"
                      android:layout_margin="10dp"
                      android:layout_weight="1"&gt;
  
                      &lt;RelativeLayout
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"&gt;
  
                          &lt;ImageView
                              android:id="@+id/iv2"
                              android:layout_width="75dp"
                              android:layout_height="75dp"
                              android:layout_centerHorizontal="true"
                              android:layout_marginTop="15dp"
                              app:srcCompat="@drawable/science" /&gt;
  
                          &lt;TextView
                              android:id="@+id/textView4"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_below="@id/iv2"
                              android:layout_centerHorizontal="true"
                              android:layout_marginTop="10dp"
                              android:fontFamily="@font/aclonica"
                              android:text="Science"
                              android:textSize="18sp" /&gt;
                      &lt;/RelativeLayout&gt;
                  &lt;/androidx.cardview.widget.CardView&gt;
  
                  &lt;androidx.cardview.widget.CardView
                      android:layout_width="0dp"
                      android:layout_height="match_parent"
                      android:layout_margin="10dp"
                      android:layout_weight="1"&gt;
  
                      &lt;RelativeLayout
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"&gt;
  
                          &lt;ImageView
                              android:id="@+id/iv3"
                              android:layout_width="75dp"
                              android:layout_height="75dp"
                              android:layout_centerHorizontal="true"
                              android:layout_marginTop="15dp"
                              app:srcCompat="@drawable/maths" /&gt;
  
                          &lt;TextView
                              android:id="@+id/textView5"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_below="@id/iv3"
                              android:layout_centerHorizontal="true"
                              android:layout_marginTop="10dp"
                              android:fontFamily="@font/aclonica"
                              android:text="Mathematics"
                              android:textSize="18sp" /&gt;
                      &lt;/RelativeLayout&gt;
                  &lt;/androidx.cardview.widget.CardView&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="175dp"
                  android:orientation="horizontal"
                  android:padding="10dp"
                  app:layout_constraintEnd_toEndOf="parent"
                  app:layout_constraintHorizontal_bias="0.0"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintTop_toBottomOf="@+id/linearLayout2"&gt;
  
                  &lt;androidx.cardview.widget.CardView
                      android:layout_width="0dp"
                      android:layout_height="match_parent"
                      android:layout_margin="10dp"
                      android:layout_weight="1"&gt;
  
                      &lt;RelativeLayout
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"&gt;
  
                          &lt;ImageView
                              android:id="@+id/iv4"
                              android:layout_width="75dp"
                              android:layout_height="75dp"
                              android:layout_centerHorizontal="true"
                              android:layout_marginTop="15dp"
                              app:srcCompat="@drawable/engg" /&gt;
  
                          &lt;TextView
                              android:id="@+id/textView6"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_below="@id/iv4"
                              android:layout_centerHorizontal="true"
                              android:layout_marginTop="10dp"
                              android:fontFamily="@font/aclonica"
                              android:text="Engineering"
                              android:textSize="18sp" /&gt;
                      &lt;/RelativeLayout&gt;
                  &lt;/androidx.cardview.widget.CardView&gt;
  
                  &lt;androidx.cardview.widget.CardView
                      android:layout_width="0dp"
                      android:layout_height="match_parent"
                      android:layout_margin="10dp"
                      android:layout_weight="1"&gt;
  
                      &lt;RelativeLayout
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"&gt;
  
                          &lt;ImageView
                              android:id="@+id/iv5"
                              android:layout_width="75dp"
                              android:layout_height="75dp"
                              android:layout_centerHorizontal="true"
                              android:layout_marginTop="15dp"
                              app:srcCompat="@drawable/tech" /&gt;
  
                          &lt;TextView
                              android:id="@+id/textView7"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_below="@id/iv5"
                              android:layout_centerHorizontal="true"
                              android:layout_marginTop="10dp"
                              android:fontFamily="@font/aclonica"
                              android:text="Technology"
                              android:textSize="18sp" /&gt;
                      &lt;/RelativeLayout&gt;
                  &lt;/androidx.cardview.widget.CardView&gt;
              &lt;/LinearLayout&gt;
          &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
      &lt;/ScrollView&gt;
  
  &lt;/androidx.drawerlayout.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>Please Help me find a solution to this. I am stuck in this for over a week now.</p>