title: NullPointerException while invoking method BottomNavigationView.setOnNavigationItemSelectedListener
body: <p>When I'm trying to switch between activies using intent in "switch case" the following error I got:
  <strong>java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.material.bottomnavigation.BottomNavigationView.setOnNavigationItemSelectedListener(com.google.android.material.bottomnavigation.BottomNavigationView$OnNavigationItemSelectedListener)' on a null object reference</strong></p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation2);
          navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
  
  
      }
  
      private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
              = new BottomNavigationView.OnNavigationItemSelectedListener() {
  
          @Override
          public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  
              switch (item.getItemId()) {
                  case R.id.ic_home:
                      return true;
                  case R.id.ic_wallet:
                      Intent intent_wallet = new Intent(MainActivity.this,Wallet.class);
                      startActivity(intent_wallet);
                      return true;
                  case R.id.ic_status:
                      Intent intent_status = new Intent(MainActivity.this,Status.class);
                      startActivity(intent_status);
                      return true;
                  case R.id.ic_history:
                      Intent intent_history = new Intent(MainActivity.this,History.class);
                      startActivity(intent_history);
                      return true;
              }
              return false;
          }
      };
  
     }
  
  </code></pre>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;androidx.coordinatorlayout.widget.CoordinatorLayout 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/container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.praveen.gupta.frontpage.MainActivity"&gt;
  
      &lt;FrameLayout
          android:id="@+id/frame_container"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior" /&gt;
  
      &lt;com.google.android.material.bottomnavigation.BottomNavigationView
          android:id="@+id/navigation2"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="bottom"
          android:background="@drawable/white_grey_border_top"
          app:labelVisibilityMode="labeled"
          app:menu="@menu/navigation" /&gt;
  
  &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p><strong>navigation.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
        &gt;
  
      &lt;item
          android:id="@+id/ic_home"
          android:icon="@drawable/ic_home_black_24dp"
          android:title="Home"
          /&gt;
  
          &lt;item
              android:id="@+id/ic_wallet"
              android:icon="@drawable/ic_account_balance_wallet_black_24dp"
              android:title="Wallet"
              /&gt;
          &lt;item
              android:id="@+id/ic_status"
              android:icon="@drawable/ic_star_border_black_24dp"
              android:title="Status"
              /&gt;
          &lt;item
              android:id="@+id/ic_history"
              android:icon="@drawable/ic_history_black_24dp"
              android:title="History"
              /&gt;
  &lt;/menu&gt;
  </code></pre>