material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.29k stars 3.06k forks source link

[TabItem] Render problem throwing NullPointerException #3259

Closed ParticleCore closed 1 year ago

ParticleCore commented 1 year ago

Description: Setting up a basic xml layout with Tablayout and TabItem children views results in render problem that prevents the layout preview from functioning correctly.

Other users are also reporting the same issue on SO: https://stackoverflow.com/questions/74271897/java-lang-nullpointerexception-at-android-content-res-resources-theme

Below is the full error stack thrown when the IDE attempts to render the layout in the preview panel

java.lang.NullPointerException
    at android.content.res.Resources_Theme_Delegate.obtainStyledAttributes(Resources_Theme_Delegate.java:74)
    at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java:1631)
    at android.content.Context.obtainStyledAttributes(Context.java:874)
    at android.widget.TextView.setTextAppearance(TextView.java:3965)
    at androidx.appcompat.widget.AppCompatTextView.setTextAppearance(AppCompatTextView.java:216)
    at com.google.android.material.textview.MaterialTextView.setTextAppearance(MaterialTextView.java:106)
    at android.widget.TextView.setTextAppearance(TextView.java:3954)
    at androidx.core.widget.TextViewCompat.setTextAppearance(TextViewCompat.java:289)
    at com.google.android.material.tabs.TabLayout$TabView.updateTab(TabLayout.java:2772)
    at com.google.android.material.tabs.TabLayout$TabView.update(TabLayout.java:2801)
    at com.google.android.material.tabs.TabLayout$TabView.setTab(TabLayout.java:2713)
    at com.google.android.material.tabs.TabLayout.createTabView(TabLayout.java:1673)
    at com.google.android.material.tabs.TabLayout.newTab(TabLayout.java:956)
    at com.google.android.material.tabs.TabLayout.addTabFromItemView(TabLayout.java:824)
    at com.google.android.material.tabs.TabLayout.addViewInternal(TabLayout.java:1730)
    at com.google.android.material.tabs.TabLayout.addView(TabLayout.java:1720)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1131)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1101)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1130)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1101)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1130)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1101)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:505)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:360)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:443)
    at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:722)
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$9(RenderTask.java:879)
    at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$3.run(RenderExecutor.kt:194)
    at com.android.tools.idea.rendering.RenderExecutor$PriorityRunnable.run(RenderExecutor.kt:292)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)

Expected behavior: Layout preview should be rendering the views without any issues.

Source code:

<com.google.android.material.tabs.TabLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    app:tabGravity="fill"
    app:tabMode="scrollable">

    <com.google.android.material.tabs.TabItem
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="a label"/>

</com.google.android.material.tabs.TabLayout>

Minimal sample app repro: Source code example is sufficient.

Android API version: Not Applicable.

Material Library version: 1.8.0

Device: Android Studio Electric Eel Patch 1

hunterstich commented 1 year ago

Hi @ParticleCore, thanks for filing an issue! Unfortunately the Material Android team has little control over Android Studio Preview issues. The Preview Editor has its own layout engine and the Studio team has to make fixes to support themes, styles, symbols, etc.

Would you be able to filing a bug with them following these instructions?

https://developer.android.com/studio/report-bugs

Closing for now but feel free to re-open if this needs attention.

Baterka commented 1 year ago

Sadly, it is still problem even in Electric El 2022.1.1 Patch 2. Anyone found solution for this issue?

imhappi commented 1 year ago

@Baterka see comment thread in https://github.com/material-components/material-components-android/issues/3007 It looks like you need at least Flamingo for it to work

Baterka commented 1 year ago

Thanks @imhappi for info. Is Flamingo Beta 5 stable a little? Or have some major bugs?

EDIT: Sadly, does not work on Flamingo Beta 5.... Same problem.