material-components-android
material-components-android copied to clipboard
[TabLayout] ResourcesNotFoundException "res/layout/design_layout_tab_icon.xml" when setting ViewPager adapter
Description:
We exprienced a crashe in production related to TabLayout when setting ViewPager adapter from Motorola running Android 11. I wonder if you're aware of the issue and if there's any fix.
Fatal Exception: android.content.res.Resources$NotFoundException: File res/layout/design_layout_tab_icon.xml from xml type layout resource ID #0x7f0d0071
at android.content.res.ResourcesImpl.loadXmlResourceParser(ResourcesImpl.java:1277)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2426)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2402)
at android.content.res.Resources.getLayout(Resources.java:1252)
at android.view.LayoutInflater.inflate(LayoutInflater.java:530)
at com.google.android.material.tabs.TabLayout$TabView.inflateAndAddDefaultIconView(TabLayout.java:2659)
at com.google.android.material.tabs.TabLayout$TabView.update(TabLayout.java:2608)
at com.google.android.material.tabs.TabLayout$TabView.setTab(TabLayout.java:2561)
at com.google.android.material.tabs.TabLayout.createTabView(TabLayout.java:1554)
at com.google.android.material.tabs.TabLayout.newTab(TabLayout.java:859)
at com.google.android.material.tabs.TabLayout.populateFromPagerAdapter(TabLayout.java:1529)
at com.google.android.material.tabs.TabLayout.setPagerAdapter(TabLayout.java:1520)
at com.google.android.material.tabs.TabLayout$AdapterChangeListener.onAdapterChanged(TabLayout.java:3440)
at androidx.viewpager.widget.ViewPager.setAdapter(ViewPager.java:549)
Android API version: Android 11
Material Library version: 1.3.0
Device: Motorola
Hi there, I'm not seeing this issue in our Catalog app, although I don't have a Motorola device or emulator so that could be why. Could you please provide some sample code to help us reproduce the crash? Also, have you verified that this issue doesn't happen on other devices/emulators?
Hi there, I'm not seeing this issue in our Catalog app, although I don't have a Motorola device or emulator so that could be why. Could you please provide some sample code to help us reproduce the crash? Also, have you verified that this issue doesn't happen on other devices/emulators?
We have yet to roll out the release with the issue completely, so to verify whether this happen on other devices, we'll have to wait until we have more data. One things to note is that we haven't updated any related dependencies that has led to this issue which only started happening in the latest release.
It's a very simple implementation of a ViewPager that caused it:
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager_detail_root"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tab_layout" />
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mViewPagerAdapter = new CustomPagerAdapter(getChildFragmentManager());
mBinding.viewPagerDetailRoot.setAdapter(mViewPagerAdapter);
}
ViewPager Library version: 1.0.0
Can you try to upgrade to the latest version of the Material library and see if it's still happening?
I'll close this issue for now due to no further info available. Please feel free to reopen it if this is still happening.