18

我显然在应用程序中的三星 Nexus 上的 1 个活动存在问题,我不明白是什么实际导致了这个问题。

java.lang.ArrayIndexOutOfBoundsException: length=244; index=1753
at android.text.MeasuredText.addStyleRun(MeasuredText.java:168)
at android.text.MeasuredText.addStyleRun(MeasuredText.java:204)
at android.text.StaticLayout.generate(StaticLayout.java:281)
at android.text.StaticLayout.<init>(StaticLayout.java:140)
at android.text.StaticLayout.<init>(StaticLayout.java:80)
at android.text.StaticLayout.<init>(StaticLayout.java:59)
at android.widget.TextView.makeSingleLayout(TextView.java:5901)
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.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1038)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:576)
at android.view.View.measure(View.java:15172)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
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.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15172)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1196)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.widget.ScrollView.onMeasure(ScrollView.java:318)
at android.view.View.measure(View.java:15172)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
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 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)

这是我的客户告诉我的导致问题的活动。这是唯一的问题。

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;



public class Protocols03_04Activity extends Activity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.protocols03_04);



    }
    //Options Menu
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.optmenu, menu);
        menu.findItem(R.id.medcom_optmenu_item).setIntent(new Intent(this, CallMedcom.class));
        menu.findItem(R.id.dispatch_optmenu_item).setIntent(new Intent(this, CallDispatch.class));
        menu.findItem(R.id.settings_optmenu_item).setIntent(new Intent(this, ProtocolsSettingsActivity.class));
        menu.findItem(R.id.mmenu_optmenu_item).setIntent(new Intent(this, ProtocolsMMenuActivity.class));
        menu.findItem(R.id.gps_optmenu_item).setIntent(new Intent(this, GPSActivity.class));
        menu.findItem(R.id.search_optmenu_item).setIntent(new Intent(this, SearchActivity.class));
        return true;
    }
}

我试图重现这个问题,但我做不到。我尝试了 2 款不同的摩托罗拉手机。

4

4 回答 4

18

似乎是 TextView 的一个已知错误。在此处此处检查类似问题

帖子里提到了银河系。第一个问题标记为将来发布,第二个问题似乎已修复。

更新

djmedic 在这里找到了解决方法

于 2012-10-11T22:49:47.650 回答
5

更新 Android Studio(或 sdk ..)后遇到同样的问题。我可以通过设置 EditText 的 inputType 来修复它。

android:inputType="text"
于 2015-08-20T12:26:01.030 回答
1

我有同样的问题。它不仅是 jellyBean 的问题。它与将跨度标签添加到 html 转换的纯文本中导致 indexOutOfBounds 异常的文本视图有关。此链接有一个解决方法。

用此自定义 textView 替换您的文本视图。如果跨度标签问题出现,它会捕获它并以纯文本形式显示内容。

public class PatchedTextView extends TextView {
public PatchedTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}
public PatchedTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
}
public PatchedTextView(Context context) {
    super(context);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    try{
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }catch (ArrayIndexOutOfBoundsException e){
        setText(getText().toString());
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
@Override
public void setGravity(int gravity){
    try{
        super.setGravity(gravity);
    }catch (ArrayIndexOutOfBoundsException e){
        setText(getText().toString());
        super.setGravity(gravity);
    }
}
@Override
public void setText(CharSequence text, BufferType type) {
    try{
        super.setText(text, type);
    }catch (ArrayIndexOutOfBoundsException e){
        setText(text.toString());
    }
}

}

于 2014-08-26T09:33:44.157 回答
0

我的经验可能对那些不想在他们的项目中添加自定义 TextView 的朋友有所帮助。

首先,我可以在 Android 模拟器(4.1.2,API 16)中重现这个错误。在此之后,我决定找出导致此错误的原因。显然 - 一些格式(这会导致创建“跨度”)。事实证明,就我而言,在两个地方替换就足够了,例如:

\"<b>@username</b>\"

有了这个:

\"@username\"

于 2014-02-02T15:55:43.330 回答