I\'m defining an ID for my fragment in the xml layout:
FragmentB fragmentB = (FragmentB) getSupportFragmentManager().findFragmentById(R.id.containerb); if(fragmentB != null) { fragmentB.showuserResponse(msg); }
Use container id as fragment id. And then check for null reference.