gpt4 book ai didi

android - android studio 中 xml 文件的设计预览不会是 "open"

转载 作者:行者123 更新时间:2023-12-05 00:13:13 28 4
gpt4 key购买 nike

我在制作一个 android 项目时遇到了一个问题。在我更新 android studio 后,我的一个 .xml 文件设计预览将无法打开。我收到 2 个错误。我已经搜索了解决方案,并且已经尝试了很多我在网上找到的东西,但没有一个能改变这种情况。

第一个是:

Render problem:
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
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$0(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.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:354)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:431)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:710)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$6(RenderTask.java:865)
at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$2.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:834)
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:74)
at androidx.appcompat.widget.AppCompatEditText.<init>(AppCompatEditText.java:69)
at androidx.appcompat.app.AppCompatViewInflater.createEditText(AppCompatViewInflater.java:209)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:127)
... 27 more

第二个是:

String index out of range:-1
Error inflating the preview (Details):
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.view.ViewGroup.<init>(ViewGroup.java:697)
at android.widget.FrameLayout.<init>(FrameLayout.java:99)
at com.android.layoutlib.bridge.MockView.<init>(MockView.java:55)
at com.android.layoutlib.bridge.MockView.<init>(MockView.java:51)
at com.android.layoutlib.bridge.MockView.<init>(MockView.java:47)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:324)
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.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:354)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:431)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:710)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$6(RenderTask.java:865)
at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$2.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:834)

这两个错误在更新完成之前不存在。

XML文件的代码是:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
tools:context=".Calculate">

<EditText
android:id="@+id/height"
android:layout_width="237dp"
android:layout_height="50dp"
android:autofillHints="none"
android:ems="10"
android:hint="@string/insert_your_height_in_cm"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.499" />

<EditText
android:id="@+id/weight"
android:layout_width="237dp"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/insert_your_weight_in_kgr"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/height"
app:layout_constraintVertical_bias="0.033" />

<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:text="@string/bmi_calculator"
app:layout_constraintBottom_toTopOf="@+id/bmiImage"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.358" />

<Button
android:id="@+id/Calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="CalculateBMI"
android:text="@string/calculate"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.136"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/weight"
app:layout_constraintVertical_bias="0.714" />

<TextView
android:id="@+id/warning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textColor="#FA0C0C"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/Calculate"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/switch1"
app:layout_constraintVertical_bias="0.588" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:textColor="#0099FF"
android:text="@string/gender"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/textView2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/weight"
app:layout_constraintVertical_bias="0.0" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/male"
android:textColor="#0099FF"
app:layout_constraintBottom_toTopOf="@+id/warning"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.228"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/weight"
app:layout_constraintVertical_bias="0.362" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="16dp"
android:text="@string/female"
android:textColor="#D1D1D1"
app:layout_constraintBottom_toTopOf="@+id/warning"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.796"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/weight"
app:layout_constraintVertical_bias="0.362" />

<ImageView
android:id="@+id/bmiImage"
android:layout_width="237dp"
android:layout_height="195dp"
android:layout_marginTop="50dp"
android:layout_marginBottom="31dp"
android:contentDescription="weight images"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/userName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_launcher_background" />

<EditText
android:id="@+id/userName"
android:layout_width="239dp"
android:layout_height="45dp"
android:layout_marginBottom="20dp"
android:ems="10"
android:hint="Insert your name"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="@+id/height"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.494"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />

<Button
android:id="@+id/saveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="73dp"
android:onClick="saveBtn"
android:text="@string/save_entry"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.351"
app:layout_constraintStart_toEndOf="@+id/Calculate"
app:layout_constraintTop_toBottomOf="@+id/weight"
app:layout_constraintVertical_bias="0.714" />
</androidx.constraintlayout.widget.ConstraintLayout>

enter image description here

最佳答案

同样的问题我之前在搜索之后遇到了很多,我了解到 EditText 中的属性 android:autofillHints 存在问题。请尝试将其注释掉或删除并尝试检查您的布局它会解决这个问题。

关于android - android studio 中 xml 文件的设计预览不会是 "open",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67548885/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com