NullPointerException when trying to use a listener for FAB in a MAP fragment [duplicate]

You are trying to find fab in fab, fab1 in fab1
You need to get those buttons from root view of your Fragment.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,  Bundle savedInstanceState) {
   View rootView = inflater.inflate(R.layout.carte_reseaux_fragment, container, false);
   fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
   .
   .
   Animation fab_open = AnimationUtils.loadAnimation(getContext(), R.anim.fab_open);
   //Actually FloatingActionButton has own implementation
   fab.setShowAnimation(fab_open);
   return rootView;
}

Leave a Comment