Android layout.xml UI消失了,当我使用材料TabLayout与项目

jum4pzuy  于 2023-05-12  发布在  Android
关注(0)|答案(2)|浏览(142)

下面是错误:

java.lang.NullPointerException: Cannot invoke "android.content.res.BridgeTypedArray.setTheme(android.content.res.Resources$Theme)" because "ta" is null
    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.inflate(LayoutInflater.java:686)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:505)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:353)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:450)
    at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:122)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:727)
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$9(RenderTask.java:884)
    at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$3.run(RenderExecutor.kt:195)
    at com.android.tools.idea.rendering.RenderExecutor$PriorityRunnable.run(RenderExecutor.kt:293)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)

材料组件依赖版本:com.google.android.material:material:1.8.0

6uxekuva

6uxekuva1#

所以显然这是一个仍然需要解决的bug,tablayout将完美地显示在设备/模拟器上,它只是不会显示在xml文件的设计视图中。所以TabLayout本身没有问题,只是在设计视图中呈现它。在这种情况下,每次进行更改时,您都必须运行应用程序来检查它,这确实是一个很大的时间浪费,但这是我们目前所能做的一切。
@编辑
实际上,我现在发现了一些问题,显然只有当您将tabItem添加到tabLayout中时才会出现这个问题。这样你就可以注解掉所有的tabItem,完成你的工作,再注解回去,然后运行应用程序。
编码愉快。

insrf1ej

insrf1ej2#

build.gradle中将材质的依赖关系更新为implementation 'com.google.android.material:material'对我有效

相关问题