title: How to fix ''boolean androidx.fragment.app.FragmentManagerImpl.isDestroyed()' on a null object reference' inside fragment with caldroid nested
body: <p>i have an activity with navigation drawer with fragments and its compiling with androidx, in one of them i want to call a fragment that contains a custom caldroid and until now it works fine, but at the moment to finish the fragment or change to another fragment the logcat call this error:</p>
  
  <p>I searched on internet and found a similar case, <a href="https://issuetracker.google.com/issues/135764330" rel="nofollow noreferrer">https://issuetracker.google.com/issues/135764330</a> and it is only related to projects that work with androidx, but i don't know how to apply the changes in the library to eliminate this error.</p>
  
  <p>Error Logcat:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: edu.usil.staffmovil, PID: 29749
      java.lang.NullPointerException: Attempt to invoke virtual method 'boolean androidx.fragment.app.FragmentManagerImpl.isDestroyed()' on a null object reference
          at androidx.fragment.app.Fragment.performDetach(Fragment.java:2849)
          at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1034)
          at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
          at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
          at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2659)
          at androidx.fragment.app.FragmentManagerImpl.dispatchDestroy(FragmentManagerImpl.java:2644)
          at androidx.fragment.app.Fragment.performDestroy(Fragment.java:2825)
          at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1028)
          at androidx.fragment.app.FragmentManagerImpl$3$1.run(FragmentManagerImpl.java:1099)
          at android.os.Handler.handleCallback(Handler.java:746)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:148)
          at android.app.ActivityThread.main(ActivityThread.java:5443)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  </code></pre>
  
  <p>Code from the fragment:</p>
  
  <pre><code>public class EventHomeFragment extends Fragment {
  
  public static final String TAG = "EventHomeFragment";
  private int diaSemana=0, diaMes=0, mes=0, anio=0, diaSelect=0;
      private CaldroidFragment caldroid;
      private int altoContenido=0, altoFila=0, posicionScroll=0, altoMesAnio = 0, altoSemana = 0, mesVisible = 0, anioVisible = 0;
      private Calendar fechaSelect;
  //More Definitions
  //...
  //...
  
  public EventHomeFragment() {
          // Required empty public constructor
      }
  
  
  
  @Override
      public void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          this.savedInstanceState = savedInstanceState;
          fechaSelect = Calendar.getInstance();
  
          Calendar cal = Calendar.getInstance();
          diaSemana = cal.get(Calendar.DAY_OF_WEEK);
          diaMes = cal.get(Calendar.DAY_OF_MONTH);
          mes = cal.get(Calendar.MONTH);
          anio = cal.get(Calendar.YEAR);
  
          mesVisible = mes;
          anioVisible = anio;
  setViewsComponentsAndEvents();
              fechaSelect.setTime(FechaUtils.getDateFromStringYYYYMMMDD( anio + "-" + ((mes + 1) &lt; 10 ? ("0" + mes) : mes) + "-" + diaMes));
          }
  
  private void setViewsComponentsAndEvents() {
  
      setDatosSemanaCabecera();
      setListarEventosPantalla();
      setCustomCaldroid();
      manejador_sliding.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (!expand) {
                  expand();
              } else {
                  collapse();
              }
          }
      });
  
      lista_eventos.post(new Runnable() {
          @Override
          public void run() {
              //Log.e("post","entramos");
              configurarViewsEventos();
          }
      });
  
  }
  
  private void setCustomCaldroid() {
  
      CaldroidListener listener = new CaldroidListener() {
  
          @Override
          public void onSelectDate(Date date, View view) {
              long currTime = System.currentTimeMillis();
              if(timeLastClick!=0){
                  if(currTime - timeLastClick &lt; ViewConfiguration.getDoubleTapTimeout()){
                      return;
                  }
              }else{
                  timeLastClick = currTime;
              }
  
              Calendar fecha = Calendar.getInstance();
              fecha.setTime(date);
              setFechaSelectedFromCalendar(fecha.get(Calendar.DAY_OF_WEEK), fecha.get(Calendar.DAY_OF_MONTH), fecha.get(Calendar.MONTH), fecha.get(Calendar.YEAR));
  
              if(lastSelected!=null){
                  Calendar lastSelectedFecha = Calendar.getInstance();
                  lastSelectedFecha.setTime(lastSelected);
                  if(fecha.get(Calendar.DAY_OF_MONTH)==lastSelectedFecha.get(Calendar.DAY_OF_MONTH) &amp;&amp;
                          fecha.get(Calendar.MONTH)==lastSelectedFecha.get(Calendar.MONTH) &amp;&amp;
                          fecha.get(Calendar.YEAR)==lastSelectedFecha.get(Calendar.YEAR)){
                      mismaFecha=true;
                  }else{
                      mismaFecha=false;
                  }
                  caldroid.clearBackgroundDrawableForDate(lastSelected);
              }else{
                  mismaFecha = true;
              }
              //si el mes que se muestra es mayor que el mes de la fecha seleccionada
              //entonces se ha seleccionado la una fecha del mes anterior
              //se esta en la primera fila
              if(anio==anioVisible) {
                  if (mesVisible &gt; mes) {
                      posicionScroll = 0;
                  }
                  if (mesVisible &lt; mes) {
                      Calendar fechaPrimero = Calendar.getInstance();
                      fechaPrimero.set(anioVisible, mesVisible, 1);
                      fechaPrimero.setMinimalDaysInFirstWeek(1);
                      int semanaMes = fechaPrimero.getActualMaximum(Calendar.WEEK_OF_MONTH);
                      posicionScroll = altoFila * (semanaMes - 1);
                  }
                  if(mesVisible==mes){
                      int semanaMes = fechaSelect.get(Calendar.WEEK_OF_MONTH);
                      posicionScroll = 0;
                      if(semanaMes&gt;1){
                          posicionScroll = altoFila*(semanaMes-1);
                      }
                  }
              }
  
              if(anioVisible&gt;anio){
                  posicionScroll = 0;
              }
  
              if(anioVisible&lt;anio){
                  Calendar fechaPrimero = Calendar.getInstance();
                  fechaPrimero.set(anioVisible, mesVisible, 1);
                  fechaPrimero.setMinimalDaysInFirstWeek(1);
                  int semanaMes = fechaPrimero.getActualMaximum(Calendar.WEEK_OF_MONTH);
                  posicionScroll = altoFila * (semanaMes - 1);
              }
  
              lastSelected = date;
  //                caldroid.setBackgroundResourceForDate(R.color.color_evento_selected, lastSelected);
              caldroid.refreshView();
  
              moveScrollToDateSelected();
  
              if(expand &amp;&amp; !mostrarMensaje &amp;&amp; moveScrollToDateSelected()){
                  collapse();
              }
  
          }
      };
  
      caldroid = new CaldroidFragment();
  
      Bundle args = new Bundle();
      Calendar fecha = Calendar.getInstance();
      fecha.setTime(FechaUtils.getDateFromStringYYYYMMMDD(anio + "-" + (mes + 1) + "-" + diaMes));
      args.putInt(CaldroidFragment.MONTH, fecha.get(Calendar.MONTH) + 1);
      args.putInt(CaldroidFragment.YEAR, fecha.get(Calendar.YEAR));
      args.putInt(CaldroidFragment.THEME_RESOURCE, R.style.CaldroidEventosUsil);
      args.putInt(CaldroidFragment.START_DAY_OF_WEEK, CaldroidFragment.MONDAY);
      args.putBoolean(CaldroidFragment.SIX_WEEKS_IN_CALENDAR, false);
  
      caldroid.setBackgroundDrawableForDate(getResources().getDrawable(R.color.color_evento_selected), fechaSelect.getTime());
      caldroid.setArguments(args);
      trans = getChildFragmentManager().beginTransaction();
      trans.addToBackStack(null);
      trans.replace(R.id.fragment_custom_caldroid, caldroid);
  //        trans.remove();
      trans.commit();
  
  
  }
  
  
  }
  </code></pre>