Fragment Swich Button Onclick Error

the button works when I use it for the first time, but when I change the fragment and press it again it stops the application that could be ??

I think the problem should be with the creation of the fragment or the change between them but I’m not sure how to fix it

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_garaje, container, false);
    botonPuerta = (CircleButton) view.findViewById(R.id.botonP);
    botonPuerta.setOnClickListener(this);
    //Detectocambios en la base de datos.
    Puerta_DataChange();
    return view;
}
private void Puerta_DataChange(){
    // Chequeo puerta
    garajeDatabase.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            String valorCambio  = (String) dataSnapshot.getValue();
            if (valorCambio.equals("abierta")){               botonPuerta.setColor(getResources().getColor(R.color.colorPrimary));
            }else{               botonPuerta.setColor(getResources().getColor(R.color.colorPrimaryDark));
            }
        }
        @Override
        public void onCancelled(DatabaseError error) {
        }
    });
}


@Override
public void onClick(final View view) {
    switch (view.getId()) {
        case R.id.botonP:
            garajeDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    String valorCambio  = (String) dataSnapshot.getValue();
                    if (valorCambio.equals("abierta")){
                        garajeDatabase.setValue("cerrada");
                    }else{
                        garajeDatabase.setValue("abierta");
                    }
                }
                @Override
                public void onCancelled(DatabaseError error) {
                    Toast.makeText(getActivity(),"ERROR BASE DE DATOS",Toast.LENGTH_SHORT).show();
                }
            });
            break;
    }
}