3

Im learning kotlin. I followed a tutorial where i should put some random text into the editText box. However whenever i put too many lines of text into the texbox, everything on the layout shrinks into the top left cornor.

I tried to invalid the cache, and also to change to another api but with no luck so far. any ideas ?

enter image description here enter image description here

This is the error android studio throws at me:

java.lang.ArrayIndexOutOfBoundsException: 16
at android.text.StaticLayout.generate(StaticLayout.java:854)
at android.text.DynamicLayout.reflow(DynamicLayout.java:609)
at android.text.DynamicLayout.generate(DynamicLayout.java:477)
at android.text.DynamicLayout.<init>(DynamicLayout.java:396)
at android.text.DynamicLayout.<init>(DynamicLayout.java:45)
at android.text.DynamicLayout$Builder.build(DynamicLayout.java:278)
at android.widget.TextView.makeSingleLayout(TextView.java:8329)
at android.widget.TextView.makeNewLayout(TextView.java:8204)
at android.widget.TextView.assumeLayout(TextView.java:8104)
at android.widget.TextView.onPreDraw(TextView.java:6742)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
at android.view.AttachInfo_Accessor.dispatchOnPreDraw(AttachInfo_Accessor.java:46)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:404)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:543)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:426)
at com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:108)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:154)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:136)
at com.android.tools.idea.rendering.RenderTask.lambda$renderInner$5(RenderTask.java:671)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Drake
  • 33
  • 6

3 Answers3

0

It is because you are using ConstraintLayout.

While using it, you have to add Constraints to each of View in order to arrange them at an appropriate place in Layout.

More info you can Check this ans

Milind Mevada
  • 3,145
  • 1
  • 14
  • 22
  • I have added constraints to each of the views but thats not what i mean. What i mean is if you enter to much text into the text view field everything shrinks together on the designer. That shouldnt be the case and it didnt one that earlier. https://imgur.com/a/eH8kJ3P But if i add a few words more everything shrinks into the top left cornor. – Drake Oct 19 '18 at 08:31
0

I have a similiar issue doing some Kotlin for Android course.

When I add text to Multiline text (editText with textMultiline input type) which is longer than what can be visible in widget, renderer crashes. Here's the stack trace given by Android Studio:

16 View Measure Failed

java.lang.ArrayIndexOutOfBoundsException: 16
at android.text.StaticLayout.generate(StaticLayout.java:854)
at android.text.DynamicLayout.reflow(DynamicLayout.java:609)
at android.text.DynamicLayout.generate(DynamicLayout.java:477)
at android.text.DynamicLayout.<init>(DynamicLayout.java:396)
at android.text.DynamicLayout.<init>(DynamicLayout.java:45)
at android.text.DynamicLayout$Builder.build(DynamicLayout.java:278)
at android.widget.TextView.makeSingleLayout(TextView.java:8329)
at android.widget.TextView.makeNewLayout(TextView.java:8204)
at android.widget.TextView.onMeasure(TextView.java:8586)
at android.view.View.measure_Original(View.java:23169)
at android.view.View_Delegate.measure(View_Delegate.java:80)
at android.view.View.measure(View.java:23133)
at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at android.support.constraint.ConstraintLayout.onMeasure_Original(ConstraintLayout.java:1572)
at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java)
at android.view.View.measure_Original(View.java:23169)
at android.view.View_Delegate.measure(View_Delegate.java:80)
at android.view.View.measure(View.java:23133)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v7.widget.ContentFrameLayout.onMeasure_Original(ContentFrameLayout.java:143)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java)
at android.view.View.measure_Original(View.java:23169)
at android.view.View_Delegate.measure(View_Delegate.java:80)
at android.view.View.measure(View.java:23133)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
at android.support.v7.widget.ActionBarOverlayLayout.onMeasure_Original(ActionBarOverlayLayout.java:401)
at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java)
at android.view.View.measure_Original(View.java:23169)
at android.view.View_Delegate.measure(View_Delegate.java:80)
at android.view.View.measure(View.java:23133)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure_Original(View.java:23169)
at android.view.View_Delegate.measure(View_Delegate.java:80)
at android.view.View.measure(View.java:23133)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:592)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:345)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:386)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:450)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:590)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

and

16 Exception raised during rendering

java.lang.ArrayIndexOutOfBoundsException: 16
at android.text.StaticLayout.generate(StaticLayout.java:854)
at android.text.DynamicLayout.reflow(DynamicLayout.java:609)
at android.text.DynamicLayout.generate(DynamicLayout.java:477)
at android.text.DynamicLayout.<init>(DynamicLayout.java:396)
at android.text.DynamicLayout.<init>(DynamicLayout.java:45)
at android.text.DynamicLayout$Builder.build(DynamicLayout.java:278)
at android.widget.TextView.makeSingleLayout(TextView.java:8329)
at android.widget.TextView.makeNewLayout(TextView.java:8204)
at android.widget.TextView.assumeLayout(TextView.java:8104)
at android.widget.TextView.onPreDraw(TextView.java:6742)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
at android.view.AttachInfo_Accessor.dispatchOnPreDraw(AttachInfo_Accessor.java:46)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:404)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:543)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:426)
at com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:108)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:154)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:136)
at com.android.tools.idea.rendering.RenderTask.lambda$renderInner$5(RenderTask.java:671)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Here is my layout:

<TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView" android:layout_marginTop="16dp" app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="16dp"/>

<Button
        android:text="Cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginEnd="16dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginBottom="16dp"
        android:id="@+id/cancelButton"/>
<Button
        android:text="OK"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/okButton"
        app:layout_constraintEnd_toStartOf="@+id/cancelButton"
        android:layout_marginEnd="32dp"
        app:layout_constraintBaseline_toBaselineOf="@+id/cancelButton"/>
<EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textMultiLine"
        android:ems="10"
        android:id="@+id/editText2"
        android:text='Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum'
        app:layout_constraintStart_toEndOf="@+id/textView"
        android:layout_marginStart="16dp" android:layout_marginTop="16dp"
        app:layout_constraintTop_toBottomOf="@+id/textView" android:layout_marginEnd="16dp"
        app:layout_constraintEnd_toEndOf="parent" android:layout_marginBottom="16dp"
        app:layout_constraintBottom_toTopOf="@+id/okButton"/>

I'm using Android Studio 3.2.1

In course widget had height greater that screen size which led to overflow of it outside main screen of the designer, in my case it just crashed.

Matthew
  • 11
  • 3
0

If you paste a multi line text in the attribute editor in Android Studio, the line breaks get removed from the string and the resulting string can be too long to handle.

If you must get a very long hard coded string in the textMultiLine widget, put it in the xml editor and add line breaks along the way.

android:text="line1
line2
line3"

I don't know what the maximum allowed length of a line is, or if this is a bug or a feature - just encountered it and worked around it like this.

jvk
  • 1
  • 3