NullPointerException : FragmentManager.beginTransaction()
FragmentManager
will be null until it is attached to the activity.So use below code ,
If it is a nested Fragment use this.getChildFragmentManager()
for your fragment class else use getActivity().getFragmentManager()
or getActivity().getSupportFragmentManager()
.
Declare your FragmentTransaction and initialize it like this
FragmentTransaction fm;
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
fm = getFragmentManager();
}
Then on your code, you can call this
Fragment fragment = new PropertyFragment();
FragmentTransaction transaction = fm.beginTransaction();
transaction.add(R.id.rent_viewer, fragment).addToBackStack(null).commit();;