1

I was trying to remove a tab from Tablayout but I was generating a Nullpointer exception.

I was using this code to remove a tab element . Of course I validate if the tab is null and the tab count. But I still receiving that error.

rootBinding?.tabs?.removeTabAt(TOYS_TAB_POSITION_INDEX)
Cristofer
  • 1,046
  • 13
  • 21

1 Answers1

1

I fixed it doing the following:

    rootBinding?.tabs?.let { tabs ->

      val toyTab = tabs.getTabAt(TOYS_TAB_POSITION_INDEX)

      toyTab?.let { tabToDelete ->

        tabToDelete.view.clearFocus()

        rootBinding?.tabs?.removeTab(tabToDelete)

      }

    }

  It fix my crash ;) .. Any comment or doubt let me know 
Cristofer
  • 1,046
  • 13
  • 21