解决java.lang.ArrayIndexOutOfBoundsException问题(android:singleLine="true")

最近发现一个java.lang.ArrayIndexOutOfBoundsException崩溃问题。


布局代码如下:

<TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:ellipsize="start"

        android:lines="1"

android:text="01234567890123456789012345678901234567890123456789" />


日志如下:

java.lang.ArrayIndexOutOfBoundsException: length=253; index=-1

at android.text.StaticLayout.calculateEllipsis(StaticLayout.java:756)

at android.text.StaticLayout.out(StaticLayout.java:720)

at android.text.StaticLayout.generate(StaticLayout.java:428)

at android.text.StaticLayout.<init>(StaticLayout.java:140)

at android.widget.TextView.makeSingleLayout(TextView.java:5884)

at android.widget.TextView.makeNewLayout(TextView.java:5741)

at android.widget.TextView.onMeasure(TextView.java:6098)

at android.view.View.measure(View.java:15172)

at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)

at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)

at android.view.View.measure(View.java:15172)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)

at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)

at android.view.View.measure(View.java:15172)

at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)

at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)

at android.view.View.measure(View.java:15172)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)

at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)

at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)

at android.view.View.measure(View.java:15172)

at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1848)

at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1100)

at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1273)

at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)

at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)

at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)

at android.view.Choreographer.doCallbacks(Choreographer.java:555)

at android.view.Choreographer.doFrame(Choreographer.java:525)

at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)

at android.os.Handler.handleCallback(Handler.java:615)

at android.os.Handler.dispatchMessage(Handler.java:92)

at android.os.Looper.loop(Looper.java:137)

at android.app.ActivityThread.main(ActivityThread.java:4745)

at java.lang.reflect.Method.invokeNative(Native Method)

at java.lang.reflect.Method.invoke(Method.java:511)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

at dalvik.system.NativeStart.main(Native Method)


结论:

android:lines="1"与android:ellipsize="start"在一起用的时候在部分手机上会出现上面的崩溃。


解决方法:把android:lines="1"改成 android:singleLine="true"



阅读更多
文章标签: android 布局
个人分类: 崩溃问题
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭