Android:EditText的问题

时间:2018-02-11 11:02:41

标签: android android-edittext kotlin

我有一个用Kotlin编写的应用程序,使用最新的支持库,最近已经开始遇到一些问题。 我自己无法重现这些问题,但我可以看到在Google Play开发者控制台上报告的类似崩溃的多次发生,在ANR和&崩溃。

EditText的定义如下:

<EditText
    android:id="@+id/editTextAmount"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:digits="0123456789"
    android:ems="10"
    android:inputType="numberDecimal"
    android:maxLines="1"
    android:textColor="@color/buttonText"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textViewAmountHeader" />

我没有对我的EditText做任何特别的事情,并且它无论如何都没有自定义样式,所以我认为这可能是框架中的一个错误。 它似乎适用于所有Android版本(4-8)

下面包含一个示例堆栈跟踪。

有没有人有提示如何解决这个问题?

java.lang.IndexOutOfBoundsException: 
  at android.text.SpannableStringBuilder.checkRange (SpannableStringBuilder.java:1018)
  at android.text.SpannableStringBuilder.getChars (SpannableStringBuilder.java:915)
  at android.text.TextUtils.getChars (TextUtils.java:83)
  at android.text.TextUtils.indexOf (TextUtils.java:116)
  at android.text.StaticLayout.generate (StaticLayout.java:200)
  at android.text.DynamicLayout.reflow (DynamicLayout.java:284)
  at android.text.DynamicLayout.<init> (DynamicLayout.java:170)
  at android.widget.TextView.makeSingleLayout (TextView.java:7578)
  at android.widget.TextView.makeNewLayout (TextView.java:7421)
  at android.widget.TextView.onMeasure (TextView.java:7854)
  at android.view.View.measure (View.java:17495)
  at android.support.constraint.ConstraintLayout.internalMeasureChildren (ConstraintLayout.java:934)
  at android.support.constraint.ConstraintLayout.onMeasure (ConstraintLayout.java:973)
  at android.view.View.measure (View.java:17495)
  at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5363)
  at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
  at android.support.v7.widget.ContentFrameLayout.onMeasure (ContentFrameLayout.java:139)
  at android.view.View.measure (View.java:17495)
  at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5363)
  at android.support.v7.widget.ActionBarOverlayLayout.onMeasure (ActionBarOverlayLayout.java:400)
  at android.view.View.measure (View.java:17495)
  at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5363)
  at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
  at android.view.View.measure (View.java:17495)
  at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5363)
  at android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1410)
  at android.widget.LinearLayout.measureVertical (LinearLayout.java:695)
  at android.widget.LinearLayout.onMeasure (LinearLayout.java:588)
  at android.view.View.measure (View.java:17495)
  at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5363)
  at android.widget.FrameLayout.onMeasure (FrameLayout.java:310)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure (PhoneWindow.java:2548)
  at android.view.View.measure (View.java:17495)
  at android.view.ViewRootImpl.performMeasure (ViewRootImpl.java:2285)
  at android.view.ViewRootImpl.measureHierarchy (ViewRootImpl.java:1396)
  at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:1595)
  at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1254)
  at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:6637)
  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:814)
  at android.view.Choreographer.doCallbacks (Choreographer.java:614)
  at android.view.Choreographer.doFrame (Choreographer.java:584)
  at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:800)
  at android.os.Handler.handleCallback (Handler.java:733)
  at android.os.Handler.dispatchMessage (Handler.java:95)
  at android.os.Looper.loop (Looper.java:146)
  at android.app.ActivityThread.main (ActivityThread.java:5602)
  at java.lang.reflect.Method.invokeNative (Native Method)
  at java.lang.reflect.Method.invoke (Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1283)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1099)
  at dalvik.system.NativeStart.main (Native Method)

编辑: 按照另一个线程中的建议设置选择没有帮助。这个问题是从框架中随机抛出的。我没有在我的代码中以编程方式处理选择。

布局非常干净,它是一个ConstraintLayout视图,EditText上面只有一个带有标题文本的TextView。

在代码中我只在启动时设置EditText中的文本,然后由用户修改它。

0 个答案:

没有答案