我如何解决 Intellij 中“设计”选项卡下 activity 布局资源的渲染问题?

How would I fix a rendering issue with my activity Layout resource under the Design tab in Intellij?

问题: 布局“设计”选项卡未呈现我的 activity 的资源布局。我不确定是不是版本问题。我确实在此处发现了一个类似的问题,但它与加载程序有关,这似乎涉及 layoutInflater.java.

我尝试了什么: 根据生成的错误提示,我已经尝试了“新布局渲染引擎”的建议,但没有任何反应。我尝试了“刷新”建议,但它也没有用。两个错误如下图所示。

我正在使用:

IntelliJ IDEA 2021.2 (Community Edition)
Build #IC-212.4746.92, built on July 27, 2021
Runtime version: 11.0.11+9-b1504.13 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
Memory: 2933M

呈现问题错误:

java.lang.reflect.InvocationTargetException
    at jdk.internal.reflect.GeneratedMethodAccessor190.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at android.view.BridgeInflater.lambda$createViewFromCustomInflater[=12=](BridgeInflater.java:259)
    at android.view.BridgeInflater.createViewFromCustomInflater(BridgeInflater.java:285)
    at android.view.BridgeInflater.onCreateView(BridgeInflater.java:122)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:928)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:948)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1002)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:309)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1121)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1095)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1124)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1095)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1124)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1095)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:325)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:369)
    at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:140)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:711)
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate(RenderTask.java:866)
    at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout.run(RenderExecutor.kt:174)
    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)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:47)
    at java.base/java.lang.String.charAt(String.java:693)
    at android.content.res.BridgeTypedArray.getType(BridgeTypedArray.java:1024)
    at android.content.res.BridgeTypedArray.getType(BridgeTypedArray.java:809)
    at android.content.res.BridgeTypedArray.getValue(BridgeTypedArray.java:778)
    at android.content.res.BridgeTypedArray.peekValue(BridgeTypedArray.java:847)
    at android.view.View.<init>(View.java:5951)
    at android.widget.TextView.<init>(TextView.java:996)
    at android.widget.EditText.<init>(EditText.java:87)
    at android.widget.EditText.<init>(EditText.java:83)
    at androidx.appcompat.widget.AppCompatEditText.<init>(AppCompatEditText.java:93)
    at androidx.appcompat.widget.AppCompatEditText.<init>(AppCompatEditText.java:88)
    at androidx.appcompat.app.AppCompatViewInflater.createEditText(AppCompatViewInflater.java:209)
    at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:127)
    ... 34 more

根据 this report,这是 autofillHints 中处理空字符串的错误,已在 Android Studio Bumblebee 中修复。

一旦 IntelliJ IDEA 将此 Android 版本与修复合并,它也可以正常工作。在那之前,您可以对 autofillHints.

使用非空字符串