I had this exception when replacing a fragment inside another fragment in a transaction where getParentFragmentManager() was called.
The solution was calling getChildFragmentManager():
Return a private FragmentManager for placing and managing Fragments inside of this Fragment.