java.lang.NullPointerException: Missing required view with ID:

Solution 1:

I encountered this issue but in my case the issue is the include flag. The workaround I found is to make the view id to be the same as the id of the root view of the included layout.

activity_layout.xml

<LinearLayout>
    <include android:id="@+id/widget1" layout="@layout/my_widget" />
</LinearLayout>

my_widget.xml

<LinearLayout
    android:id="@+id/widget1">
</LinearLayout>

Solution 2:

If someone is getting this with TabLayout and ViewBinding enabled then you might have set id for the TabItem. Removing id from TabItem rseolved the issue for me.