Tonnie
Tonnie

Reputation: 8122

Motion Editor Preview not Loading

I am working on app using MotionLayout feature but the MotionLayout Editor is acting up and is not showing the preview when I click the Design tab.

I am getting is a blank preview with a Rendering error which I have been trying to solve to no avail.

This is what I have.

enter image description here

This is the error I am getting

java.lang.reflect.InvocationTargetException
    at jdk.internal.reflect.GeneratedMethodAccessor586.invoke(Unknown Source)
atjava.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: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)
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.view.ViewGroup.<init>(ViewGroup.java:697)
    at android.widget.AdapterView.<init>(AdapterView.java:260)
    at android.widget.AbsSpinner.<init>(AbsSpinner.java:74)
    at android.widget.Spinner.<init>(Spinner.java:246)
    at android.widget.Spinner.<init>(Spinner.java:213)
    at android.widget.Spinner.<init>(Spinner.java:163)
    at androidx.appcompat.widget.AppCompatSpinner.<init>(AppCompatSpinner.java:209)
    at androidx.appcompat.widget.AppCompatSpinner.<init>(AppCompatSpinner.java:180)
    at androidx.appcompat.widget.AppCompatSpinner.<init>(AppCompatSpinner.java:160)
    at androidx.appcompat.widget.AppCompatSpinner.<init>(AppCompatSpinner.java:144)
    at androidx.appcompat.app.AppCompatViewInflater.createSpinner(AppCompatViewInflater.java:214)
    at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:131)
    ... 26 more

I am on Android 4.2 and I am using this dependency for the Constraint Layou.

implementation "androidx.constraintlayout:constraintlayout:2.1.0-beta02"

The classpath is classpath "com.android.tools.build:gradle:4.2.0

This is my gradle version distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

I have tried restarting, invalidating cache, cleaning, rebuilding, delete lib fold in .idea and also deleting app/build file but still cannot get the preview and the Rendering Error Persists.

This is my link to the project and will appreciate any help to resolve this.

Upvotes: 0

Views: 704

Answers (1)

Tonnie
Tonnie

Reputation: 8122

After toying with this for what felt like an eternity, I realized the problem was caused by an attribute on my Spinner.

enter image description here

After removing this attribute MotionLayout Editor preview works!

Upvotes: 3

Related Questions