How to decide On a null object reference?

Good day! Help solve the problem.
Error:
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.gnegno.horoscope.FragmentFirst.sendData(java.lang.String)' on a null object reference
at com.gnegno.horoscope.startActivity.onNavigationItemSelected(startActivity.java:118) (fragment1.sendData(S1))

Understand that where it is necessary to rearrange the rows, but I do not understand where.
For those who think that String S = (String) getMapLastIntent().get("taurus") is null, it is not. Elsewhere the same activity all the rules. And checked with String S = (String) ="taurus"; the same error.

Further, while case R. id.nav_gallery: apparently the same problem, another method of transmission is through intents, without errors works, but just not broadcasting anything.
@SuppressWarnings("StatementWithEmptyBody")
@Override
 public boolean onNavigationItemSelected(MenuItem item) {

 // Create a new fragment
 Fragment fragment = null;
 Class fragmentClass = null;

 // Handle navigation view item clicks here.
 int id = item.getItemId();

 switch (id) {
 case R. id.nav_camera:
 FragmentFirst fragment1 = (FragmentFirst)getSupportFragmentManager()
.findFragmentById(R. id.container);

 fragmentClass = FragmentFirst.class;
 String S1 = (String) getMapLastIntent().get("taurus");
fragment1.sendData(S1);

break;
 case R. id.nav_gallery:
 /*String S = (String) getMapLastIntent().get("taurus");*/
 String S = "taurus";
 Intent intent = new Intent();
 intent.putExtra("taurus", S);
getApplicationContext().sendBroadcast(intent);

 fragmentClass = FragmentSecond.class;
break;
 case R. id.nav_slideshow:

break;
 case R. id.nav_manage:

break;
 case R. id.nav_share:

break;
}

 try {
 assert fragmentClass != null;
 fragment = (Fragment) fragmentClass.newInstance();

 } catch (Exception e) {
e.printStackTrace();
}

 // Insert the fragment replacing current fragment
 FragmentManager fragmentManager = getSupportFragmentManager();

 fragmentManager.beginTransaction().replace(R. id.container, fragment).commit();

 // Allocate the selected menu item in the blind
item.setChecked(true);
 // Print the selected item in the header
setTitle(item.getTitle());

 DrawerLayout drawer = (DrawerLayout) findViewById(R. id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);

 return true;
 }
June 3rd 19 at 19:29
0 answer

Find more questions by tags AndroidJava