javaandroid-studioandroid-layoutandroid-studio-4.2

Android Studio XML Render Problem - String Index Out Of Range:-1


When I adding android:autoFillHints="" attribute to the XML code of activity, design screen suddenly started giving an error.

First, the activity layout that I editing did not show anything on the design screen and there was error in just the activity layout that I editing. Then, I tried to solve there are my steps which did not work (nothing else worked.):

  1. I change the API version to 29 and 28 from 30. It did not worked.
  2. I rewrite all the XML code at the activity layout that I editted. It did not worked.

I search Google and Stack Over Flow but I did not see any solve. The answers were about JavaFX or pure java code that String index is out of range.

After that, I decided to edit other activity layouts and when I edit other activity layouts started giving errors.

The XML file that I get error is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".noteDetails"
    android:paddingHorizontal="20dp"
    android:orientation="vertical">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp">

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="@font/ubuntubold"
            android:text="@string/note_details"
            android:textColor="@color/yellow"
            android:textSize="25sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:ignore="MissingConstraints" />

        <ImageButton
            android:id="@+id/saveNoteButton"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="@drawable/ic_save_note_changes"
            android:visibility="gone"
            android:backgroundTint="@color/green"
            android:layout_marginEnd="20dp"
            app:layout_constraintEnd_toStartOf="@id/deleteNoteButton"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            android:contentDescription="@string/save_updates_button" />

        <ImageButton
            android:id="@+id/editNoteButton"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="@drawable/ic_edit_note"
            android:backgroundTint="@color/blue"
            android:layout_marginEnd="20dp"
            app:layout_constraintEnd_toStartOf="@id/deleteNoteButton"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            android:contentDescription="@string/edit_note_button" />

        <ImageButton
            android:id="@+id/deleteNoteButton"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="@drawable/ic_delete_note"
            android:backgroundTint="@color/pink"
            app:layout_constraintEnd_toStartOf="@+id/goBackButton"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            android:layout_marginEnd="20dp"
            android:contentDescription="@string/delete_note_button" />

        <ImageButton
            android:id="@+id/goBackButton"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="@drawable/ic_go_back"
            android:backgroundTint="@color/darkblue"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:contentDescription="@string/go_to_main_menu_button" />

    </androidx.constraintlayout.widget.ConstraintLayout>

    <View
        android:layout_width="wrap_content"
        android:layout_height="10dp"
        android:background="@drawable/horizontal_line"/>

    <LinearLayout
        android:id="@+id/editNoteLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginVertical="20dp"
        android:padding="8dp"
        android:background="@drawable/ic_note_detailed_text_frame">
        
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp">

            <EditText
                android:id="@+id/noteTitleDetailed"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="@font/ubunturegular"
                android:textStyle="bold"
                android:hint="@string/note_title"
                android:background="@null"
                android:inputType="text"
                android:textSize="20sp"
                android:textColor="@color/darkblue"
                android:maxLength="30"
                app:layout_constraintStart_toStartOf="parent"
                tools:ignore="MissingConstraints"
                android:autofillHints="" />

            <View
                android:layout_width="100dp"
                android:layout_height="3dp"
                android:layout_gravity="start"
                android:layout_marginTop="5dp"
                android:background="@drawable/ic_note_title_and_text_divider"
                app:layout_constraintTop_toBottomOf="@id/noteTitleDetailed"
                app:layout_constraintBottom_toBottomOf="parent"
                tools:ignore="MissingConstraints" />

            <TextView
                android:id="@+id/noteDateDetailed"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="@font/ubuntulight"
                android:textSize="12sp"
                android:layout_marginTop="5dp"
                android:text="@string/example_date"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@id/noteTitleDetailed"/>

        </androidx.constraintlayout.widget.ConstraintLayout>

        <EditText
            android:id="@+id/noteTextDetailed"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:fontFamily="@font/ubunturegular"
            android:textSize="16sp"
            android:textColor="@color/darkblue"
            android:hint="@string/note_content"
            android:lines="10"
            android:ems="10"
            android:maxLength="500"
            android:background="@null"
            tools:ignore="MissingConstraints"
            android:layout_marginBottom="10dp"
            android:autofillHints="" />
        
    </LinearLayout>
</LinearLayout>

I control the code again and again and I did not notice any problem about XML code. And when I compile the code, program run with not problem.

Error codes and images are:

Render Problem Error Code:

java.lang.reflect.InvocationTargetException
    at jdk.internal.reflect.GeneratedMethodAccessor953.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$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.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: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)
    ... 34 more

Render Problem Error Image: Render Problem Error Image

Stack Trace Error Code:

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

Stack Trace Error Image: Stack Trace Error Image

If anything is missing, let me know and I'll add it right away. Thank you from now.


Solution

  • The answer is easy, just delete the all of android:autofillHints="" line in <EditText/>. And XML Render working again.