24

我很难弄清楚这一点。我无法在我的手机上重现(nexus 4)。似乎不会影响所有设备,但我有足够的报告令人沮丧地看到它不断发生。

java.lang.ArrayIndexOutOfBoundsException: length=10; index=10
at android.text.StaticLayout.calculateEllipsis(StaticLayout.java:938)
at android.text.StaticLayout.out(StaticLayout.java:859)
at android.text.StaticLayout.generate(StaticLayout.java:524)
at android.text.StaticLayout.<init>(StaticLayout.java:147)
at android.widget.TextView.makeSingleLayout(TextView.java:6583)
at android.widget.TextView.makeNewLayout(TextView.java:6429)
at android.widget.TextView.onMeasure(TextView.java:6807)
at android.view.View.measure(View.java:16047)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1232)
at android.widget.TableRow.onMeasure(TableRow.java:114)
at android.view.View.measure(View.java:16047)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.TableLayout.measureChildBeforeLayout(TableLayout.java:464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.TableLayout.measureVertical(TableLayout.java:476)
at android.widget.TableLayout.onMeasure(TableLayout.java:439)
at android.view.View.measure(View.java:16047)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
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:16047)
at android.widget.ListView.measureScrapChild(ListView.java:1190)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1255)
at android.widget.ListView.onMeasure(ListView.java:1165)
at android.view.View.measure(View.java:16047)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
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:16047)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16047)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16047)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2418)
at android.view.View.measure(View.java:16047)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2129)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1282)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1493)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1179)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4861)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5293)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
4

6 回答 6

38

需要设置属性android:lines="1" android:singleLine="true" https://code.google.com/p/android/issues/detail?id=33868

于 2013-09-02T00:22:32.797 回答
4

这是一个错误。在android本身报告请忽略使用start。 https://code.google.com/p/android/issues/detail?id=33868

于 2016-05-09T13:30:58.090 回答
4

问题

  1. 如果我们设置android:maxLines="1" android:ellipsize="middle",那么我们的应用程序会在某些设备中崩溃。

解决方案

  1. Android 文档说,当我们设置"android:maxLines"属性时,"android:ellipsize"仅支持EndMarquee属性。

参考

设置椭圆大小

在 API 级别 1 中添加

void setEllipsize (TextUtils.TruncateAt where)

使文本中比视图宽度长的单词变成椭圆而不是在中间断开。您可能还需要 setSingleLine() 或 setHorizo​​ntallyScrolling(boolean) 将文本限制为单行。使用 null 关闭省略号。如果已使用 setMaxLines(int) 设置两行或多行,则仅支持 END 和 MARQUEE(其他椭圆化类型不会做任何事情)。

于 2017-08-01T15:40:01.810 回答
0

他们至少应该将这个添加到 Lint 中!:S 您可以使用自定义文本视图来解决此问题。

public class MyTextView extends TextView {
    public MyTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MyTextView(Context context) {
        super(context);
        init();
    }

    private void init() {

        // this is to overcome the calculateEllipsis bug in some versions of android, I spotted it on 4.4.4 and 4.4.3
        // see https://code.google.com/p/android/issues/detail?id=33868

        if (Build.VERSION.SDK_INT >= 16) {
            if (getMaxLines() == 1) {
                setSingleLine(true);
            }
        }
    }
}

在您的 xml 中引用 MyTextView 而不是普通的 textview。

于 2015-03-23T09:19:41.247 回答
-3

Array索引从减号开始0和结束..所以将循环限制为.array length19

于 2013-06-11T14:53:22.860 回答
-4

改变 for 循环看起来像这样

你的数组长度为 0 到 10

for (int i=0; i<9; i++)
{
      System.out.println("value is  ofposition"+yourArrayList[i]);
}
于 2016-07-22T06:43:14.393 回答