Reputation: 51
I cant see the preview of this layout, is the only with this problem, can build and everything else is ok. Latout
<?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=".PriceActivity">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabAddCart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_baseline_add_shopping_cart_24" />
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="horizontal">
<EditText
android:id="@+id/editCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:autofillHints=""
android:ems="10"
android:hint="Code"
android:inputType="number|text" />
<ImageButton
android:id="@+id/imgbScan"
android:layout_width="50dp"
android:layout_height="50dp"
android:adjustViewBounds="true"
android:background="@drawable/btn_primary"
android:cropToPadding="true"
android:padding="8dp"
android:scaleType="fitCenter"
android:tint="#fff"
app:srcCompat="@drawable/ic_baseline_qr_code_scanner_24" />
</LinearLayout>
<ImageView
android:id="@+id/imageView2"
android:layout_width="200dp"
android:layout_height="200dp"
android:visibility="gone"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
<TextView
android:id="@+id/txtPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#2E7D32"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAlignment="center"
android:textSize="24sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
the error message is: String index out of range: -1
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.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)
the problem is new, is probable after i update android studio, i don't now when exactly have this problem but is only in this layout. app works correctly but the preview and content tree of design view in android studio is not showing.
Upvotes: 5
Views: 467
Reputation: 1559
The issue lies in android:autofillHints=""
. Remove android:autofillHints=""
from EditText
and add android:importantForAutofill="no"
. Above EditText
should look like below:
<EditText
android:id="@+id/editCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:importantForAutofill="no"
android:ems="10"
android:hint="Code"
android:inputType="number|text" />
After applying above change, please close this xml
file and re-open it to refresh the rendering of Views.
Upvotes: 3
Reputation: 11
I had this exact problem and I found this solution to be working for me. It seems like it might be the solution for you too.
All credit goes to Jin with their post that's available here
Upvotes: 0