Android java.lang.ArrayIndexOutOfBoundsException:length = 10;指数= 10

时间:2013-06-11 14:52:24

标签: java android

我很难搞清楚这一个。我无法在手机上重现(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)

6 个答案:

答案 0 :(得分:34)

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

答案 1 :(得分:3)

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

答案 2 :(得分:2)

<强>问题

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

    1. Android文档说,当我们设置"android:maxLines"属性时,"android:ellipsize"属性只支持结束选取框
    2. <强>参考

      <强> setEllipsize

      在API级别1中添加

      void setEllipsize (TextUtils.TruncateAt where)
      

      使文本中长于视图宽度的单词被椭圆化而不是在中间断开。您可能还需要setSingleLine()或setHorizo​​ntallyScrolling(boolean)将文本约束为单行。使用null关闭ellipsizing。 如果setMaxLines(int)用于设置两行或更多行,则仅支持END和MARQUEE(其他椭圆化类型不会执行任何操作)。

答案 3 :(得分: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。

答案 4 :(得分:-2)

Array索引从0开始,以array length减去1结束。因此限制循环为9

答案 5 :(得分:-4)

更改for循环看起来像这样

  

您的数组长度为0到10

for (int i=0; i<9; i++)
{
      System.out.println("value is  ofposition"+yourArrayList[i]);
}