如何解决Android Studio xml Preview Window 预览不出来
ava.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.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: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 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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/ImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0.5"
app:layout_constraintStart_toStartOf="@+id/linearLayout3"
app:layout_constraintTop_toTopOf="@+id/linearLayout3"
app:srcCompat="@drawable/work_out" />
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="100dp"
android:fontFamily="sans-serif-black"
android:gravity="center"
android:text="@string/sign_up"
android:textColor="@color/black"
android:textSize="30sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="@+id/name"
android:layout_width="135dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/name"
android:inputType="textPersonName"
android:textColorHint="@color/black" />
<RadioGroup
android:id="@+id/gender"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/male" />
<RadioButton
android:id="@+id/female"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/female" />
</RadioGroup>
</LinearLayout>
<EditText
android:id="@+id/birth"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/birth"
android:inputType="textPersonName"
android:textColorHint="@color/black" />
<LinearLayout
android:layout_width="323dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="@+id/sign_up_id"
android:layout_width="142dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/ID"
android:inputType="textPersonName"
android:textColorHint="@color/black" />
<Button
android:id="@+id/id_check_btn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="@string/id_check"
android:textSize="12sp" />
</LinearLayout>
<EditText
android:id="@+id/sign_up_pw"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/password"
android:inputType="textPassword"
android:textColorHint="@color/black" />
<Button
android:id="@+id/signup_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="100dp"
android:text="@string/sign_up" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
顶部是下面XML代码中UI预览窗口的错误部分。 如果你看图片,你在预览窗口中看不到UI,屏幕就这样出来了。我找不到解决方法。 感谢您阅读。请回复。
解决方法
试试这个,它会起作用
<?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">
<ImageView
android:id="@+id/ImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0.5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/linearLayout3"
app:srcCompat="@drawable/johanesburg" />
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ImageView">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="100dp"
android:fontFamily="sans-serif-black"
android:gravity="center"
android:text="@string/sign_up"
android:textColor="@color/black"
android:textSize="30sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="@+id/name"
android:layout_width="135dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/name"
android:inputType="textPersonName"
android:textColorHint="@color/black" />
<RadioGroup
android:id="@+id/gender"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/male" />
<RadioButton
android:id="@+id/female"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/female" />
</RadioGroup>
</LinearLayout>
<EditText
android:id="@+id/birth"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/birth"
android:inputType="textPersonName"
android:textColorHint="@color/black" />
<LinearLayout
android:layout_width="323dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="@+id/sign_up_id"
android:layout_width="142dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/ID"
android:inputType="textPersonName"
android:textColorHint="@color/black" />
<Button
android:id="@+id/id_check_btn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="@string/id_check"
android:textSize="12sp" />
</LinearLayout>
<EditText
android:id="@+id/sign_up_pw"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/password"
android:inputType="textPassword"
android:textColorHint="@color/black" />
<Button
android:id="@+id/signup_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="100dp"
android:text="@string/sign_up" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。