In addition to the fragments, I want to add a transition to my navigation drawer as well.
public boolean onNavigationItemSelected(MenuItem item) { int id = item.getItemId(); Fragment fragment = null; if (id == R.id.nav_camera) { fragment = new MainFragment(); } else if (id == R.id.nav_gallery) { fragment = new SecondFragment(); } else if (id == R.id.nav_slideshow) { startActivity(new Intent(getApplicationContext(), MainActivity.class)); } android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, fragment); fragmentTransaction.commit(); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } If there are no problems when navigating through fragments, then when you go to MainActivity, you get an error
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference