title: Android Bottom Navigation Activity gives a Null Pointer Exception in onCreate
body: <p>I added a Bottom Navigation Activity to my project but when i start the relevant activity it gives out a Null Pointer Exception.</p>
  
  <p>It says that the exception is fired at line number 28</p>
  
  <blockquote>
    <p>at lk.apiit.eea.mobile.Activities.CompanyProfile.onCreate(CompanyProfile.java:28)</p>
  </blockquote>
  
  <p>Following is the Exception and the Code
  PLease help me fix this.. Thank you</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{lk.apiit.eea.mobile/lk.apiit.eea.mobile.Activities.CompanyProfile}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.app.ActionBar.setTitle(java.lang.CharSequence)' on a null object reference
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2720)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2781)
      at android.app.ActivityThread.-wrap12(ActivityThread.java)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1508)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:241)
      at android.app.ActivityThread.main(ActivityThread.java:6274)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.app.ActionBar.setTitle(java.lang.CharSequence)' on a null object reference
      at androidx.navigation.ui.ActionBarOnDestinationChangedListener.setTitle(ActionBarOnDestinationChangedListener.java:48)
      at androidx.navigation.ui.AbstractAppBarOnDestinationChangedListener.onDestinationChanged(AbstractAppBarOnDestinationChangedListener.java:100)
      at androidx.navigation.NavController.addOnDestinationChangedListener(NavController.java:218)
      at androidx.navigation.ui.NavigationUI.setupActionBarWithNavController(NavigationUI.java:220)
      at lk.apiit.eea.mobile.Activities.CompanyProfile.onCreate(CompanyProfile.java:28)
      at android.app.Activity.performCreate(Activity.java:6720)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2673)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2781) 
      at android.app.ActivityThread.-wrap12(ActivityThread.java) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1508) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:241) 
      at android.app.ActivityThread.main(ActivityThread.java:6274) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
  </code></pre>
  
  <p>An this is the code in onCreateMethod</p>
  
  <pre><code> @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_company_profile);
      BottomNavigationView navView = findViewById(R.id.nav_view);
      // Passing each menu ID as a set of Ids because each
      // menu should be considered as top level destinations.
      AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
              R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
              .build();
      NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
      NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
      NavigationUI.setupWithNavController(navView, navController);
  }
  </code></pre>