微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android Studio 主活动消失,呈现问题和字符串索引超出范围

如何解决Android Studio 主活动消失,呈现问题和字符串索引超出范围

TLDR:我的主要活动已经消失

什么:活动是通过布局制作的登录页面

时间:在我确定清除并运行应用程序的所有错误之后

我试过:通过谷歌查找,stackoverflow 的类似问题,然后点击 Layout Inflator

Picture of Main Activity Page /// Picture of what it looked like before

这是我的代码

<?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"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/EmailAddressEditText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="52dp"
        android:ems="10"
        android:hint="@string/email_address"
        android:inputType="textEmailAddress"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/LoginwithyouremailorpasswordTextView"
        android:autofillHints="" />

    <TextView
        android:id="@+id/subBackButtontextview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/back_button"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/WelcomeBackTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="24dp"
        android:text="@string/welcome_back"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/subBackButtontextview" />

    <EditText
        android:id="@+id/editTextTextPassword"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:ems="10"
        android:hint="@string/password"
        android:inputType="textPassword"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/EmailAddressEditText"
        android:autofillHints="" />

    <TextView
        android:id="@+id/LoginwithyouremailorpasswordTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="44dp"
        android:text="@string/log_in_with_your_email_or_password"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/WelcomeBackTextView" />

    <Button
        android:id="@+id/LoginButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="26dp"
        android:text="@string/log_in"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/editTextTextPassword" />

    <TextView
        android:id="@+id/Ortextview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="24dp"
        android:text="@string/or"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/LoginButton" />

    <Button
        android:id="@+id/ContinueWithGooglebutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/continue_with_google"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/subLineunderortextView" />

    <TextView
        android:id="@+id/subLineunderortextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="11dp"
        android:text="@string/linesub"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/Ortextview" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/continue_with_facebook"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ContinueWithGooglebutton" />

    <TextView
        android:id="@+id/ForgotyourpasswordtextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"
        android:text="@string/forgot_your_password"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button3" />

    <TextView
        android:id="@+id/subresetittextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="28dp"
        android:layout_marginLeft="28dp"
        android:text="@string/reset_it"
        app:layout_constraintStart_toEndOf="@+id/ForgotyourpasswordtextView"
        app:layout_constraintTop_toTopOf="@+id/ForgotyourpasswordtextView" />
</androidx.constraintlayout.widget.ConstraintLayout>

这里是错误

    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: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)
    ... 27 more

这方面很新,我对编码一无所知,因此也欢迎任何一般提示。尤其是学习术语的好地方。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。