IndexOutOfBoundsException异常三星设备 [英] IndexOutOfBoundsException on Samsung devices

查看:2258
本文介绍了IndexOutOfBoundsException异常三星设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到关于三星Galaxy S5抛出IndexOutOfBoundsException和注3和4。它没有引用我的code。有没有人遇到过吗?我一直没能找到就在这里任何东西。

上的EditText

在尝试这似乎是偶尔发生的长期单击粘贴的东西。

编辑:

我用一个简单的EditText字段(不是在ListView控件或微调)。有大约28个字符的提示。我通过 clearFocus 几次切换对焦和我使用的是 setOnEditorActionListener setOnFocusChangeListener 该控件的片段连接到活动。

编辑#2:

我已经能够通过努力在长期的EditText preSS尝试粘贴的东西成功地复制它。它只有当文本已经在和的EditText我很久preSS文本的权利,而不是在它发生。此外,一定的EditText没有焦点。

通过创建自定义的EditText并覆盖一些方法的任何可能的解决方案?

  java.lang.IndexOutOfBoundsException:setSpan(11 ... 11)结束以后长度为0
   在android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1024)
   在android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:594)
   在android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:590)
   在android.text.Selection.setSelection(Selection.java:116)
   在android.text.Selection.setSelection(Selection.java:127)
   在android.widget.Editor.performLongClick(Editor.java:1008)
   在android.widget.TextView.performLongClick(TextView.java:10637)
   在android.view.View $ CheckForLong press.run(View.java:19482)
   在android.os.Handler.handleCallback(Handler.java:733)
   在android.os.Handler.dispatchMessage(Handler.java:95)
   在android.os.Looper.loop(Looper.java:146)
   在android.app.ActivityThread.main(ActivityThread.java:5678)
   在java.lang.reflect.Method.invokeNative(本机方法)
   在java.lang.reflect.Method.invoke(Method.java:515)
   在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1291)
   在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
   在dalvik.system.NativeStart.main(本机方法)

code:

  editText.setOnEditorActionListener(新OnEditorActionListener(){        公共布尔onEditorAction(TextView的V,INT actionId,KeyEvent的事件){
            字符串SEARCHTEXT = v.getText()的toString()。            FragmentSearchList fragmentSearchList =(FragmentSearchList)getChildFragmentManager()findFragmentByTag(FRAGMENT_SEARCH_LIST_TAG)。            如果(fragmentSearchList!= NULL){
                fragmentSearchList.executeSearch(SEARCHTEXT);
            }            返回true;
        }    });editText.setOnFocusChangeListener(新OnFocusChangeListener(){        @覆盖
        公共无效onFocusChange(查看视图,布尔hasFocus){
            如果(hasFocus){                FragmentManager fragmentManager = getChildFragmentManager();                片段片段= fragmentManager.findFragmentByTag(FRAGMENT_SEARCH_LIST_TAG);                如果(片段== NULL){                    editText.setText(NULL);                    FragmentSearchList fragmentSearchList = FragmentSearchList.newInstance();                    FragmentTransaction fragmentSearchListTransaction = fragmentManager.beginTransaction();
                    fragmentSearchListTransaction.add(R.id.viewGroupFragmentSearchListContainer,fragmentSearchList,FRAGMENT_SEARCH_LIST_TAG);
                    fragmentSearchListTransaction.addToBackStack(NULL);
                    fragmentSearchListTransaction.commit();                }
            }
            其他{                如果(!isRemovingOrPartOfRemovalChain()){
                    editText.setText(mAreaName);
                    getChildFragmentManager()popBackStack()。
                }            }
        }    });
公共布尔isRemovingOrPartOfRemovalChain(){    如果(isRemoving()){
        返回true;
    }    片段片段= this.getParentFragment();    如果(片段!= NULL){
        如果(((MainFragment)片段).isRemovingOrPartOfRemovalChain()){
            返回true;
        }
        其他{
            返回false;
        }
    }    其他{
        回报(this.getActivity()isFinishing());
    }}


解决方案

喜其所有不例外:第一,进来的三星设备唯一的

  java.util.ArrayList.throwIndexOutOfBoundsException:无效指数3,大小为3

这意味着你有有3个元素,你可以得到每个元素像0,1,2位置的ArrayList。而你试图读取不存在到ArrayList中第4个元素。

  java.util.ArrayList.throwIndexOutOfBoundsException:无效指数为0,大小为0

这意味着你有一个空的ArrayList,而你试图读取第一个元素。

ArrayIndexOutOfBoundsException异常 - 例如

这是数组索引越界异常是Java异常抛出,由于这样的事实,该计划试图在这是一个数组的限制之外的位置来访问一个元素,因此出界的字样。换句话说,该程序正试图即数组边界外的索引来访问的元素。要理解数组边界,让我们考虑如下图:

他上面图片中包含一个由7个元素的数组。数组中的每个元素都有自己的索引/位置。在Java中,一个索引总是以0开始,并以阵列-1的长度结束。例如,该阵列上方由7的元素,因此它的索引从0开始,并与图6(7-1)结束。试图以比6小于0以上的索引来访问一个元件将导致的Java抛出一个ArrayIndexOutOfBoundsException

了解更多关于 ArrayIndexOutOfBoundsException异常 - 例如,原因及放大器;修复

I'm getting an IndexOutOfBoundsException on Samsung Galaxy S5 and Note 3 and 4. It doesn't reference my code. Has anyone encountered this? I haven't been able to find anything on here.

It appears to be occasionally happening when try to long-click on the EditText to paste something in.

Edit:

I'm using a simple EditText field (not in ListView or Spinner). There's a hint of around 28 characters. I'm toggling the focus via clearFocus a few times and I'm using a setOnEditorActionListener and setOnFocusChangeListener that control attaching a fragment to the Activity.

Edit #2:

I've been able to successfully reproduce it by trying to long press on the EditText to try to paste something. It only happens when there is text already in the EditText and I long press to the RIGHT of the text, not on it. Also, the EditText must not have focus.

Any possible solution by creating a custom EditText and overriding some methods?

java.lang.IndexOutOfBoundsException: setSpan (11 ... 11) ends beyond length 0
   at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1024)
   at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:594)
   at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:590)
   at android.text.Selection.setSelection(Selection.java:116)
   at android.text.Selection.setSelection(Selection.java:127)
   at android.widget.Editor.performLongClick(Editor.java:1008)
   at android.widget.TextView.performLongClick(TextView.java:10637)
   at android.view.View$CheckForLongPress.run(View.java:19482)
   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:5678)
   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:1291)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
   at dalvik.system.NativeStart.main(Native Method)

Code:

editText.setOnEditorActionListener(new OnEditorActionListener() {

        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            String searchText = v.getText().toString();

            FragmentSearchList fragmentSearchList = (FragmentSearchList) getChildFragmentManager().findFragmentByTag(FRAGMENT_SEARCH_LIST_TAG);

            if(fragmentSearchList != null){
                fragmentSearchList.executeSearch(searchText);
            }

            return true;
        }

    });

editText.setOnFocusChangeListener(new OnFocusChangeListener(){

        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if(hasFocus){

                FragmentManager fragmentManager = getChildFragmentManager();

                Fragment fragment = fragmentManager.findFragmentByTag(FRAGMENT_SEARCH_LIST_TAG);

                if(fragment == null){

                    editText.setText(null);

                    FragmentSearchList fragmentSearchList = FragmentSearchList.newInstance();

                    FragmentTransaction fragmentSearchListTransaction = fragmentManager.beginTransaction();
                    fragmentSearchListTransaction.add(R.id.viewGroupFragmentSearchListContainer, fragmentSearchList, FRAGMENT_SEARCH_LIST_TAG);
                    fragmentSearchListTransaction.addToBackStack(null);
                    fragmentSearchListTransaction.commit();

                }
            }
            else{

                if(!isRemovingOrPartOfRemovalChain()){
                    editText.setText(mAreaName);
                    getChildFragmentManager().popBackStack();
                }

            }
        }

    });


public boolean isRemovingOrPartOfRemovalChain(){

    if(isRemoving()){
        return true;
    }

    Fragment fragment = this.getParentFragment();

    if(fragment != null){
        if(((MainFragment)fragment).isRemovingOrPartOfRemovalChain()){
            return true;
        }
        else{
            return false;
        }
    }

    else{
        return(this.getActivity().isFinishing());
    }

}

解决方案

hi first of all its not exception that come in Samsung devices only

java.util.ArrayList.throwIndexOutOfBoundsException: Invalid index 3, size is 3

It means you have ArrayList which having 3 elements where you can get each element like 0,1,2 positions. And you are trying to read 4th element which does not exists into ArrayList.

java.util.ArrayList.throwIndexOutOfBoundsException: Invalid index 0, size is 0

It means you have a empty ArrayList, and you are trying to read 1st element.

ArrayIndexOutOfBoundsException - Examples

An array-index out of bounds exception is a Java exception thrown due to the fact that the program is trying to access an element at a position that is outside an array limit, hence the words "Out of bounds". In other words, the program is trying to access an element at an index that is outside the array bounds. To understand array bounds, let us consider the following diagram:

he picture above contains an array that consists of 7 elements. Each element in the array has its own index/position. In Java, an index always starts with 0 and ends with the length of the array -1. For example, the array above consists of 7 elements, therefore it's indices start from 0 and end with 6 (7-1). Attempting to access an element with an index less than 0 or more than 6 will cause Java to throw an ArrayIndexOutOfBoundsException.

Read more about ArrayIndexOutOfBoundsException - Examples, Causes & Fixes

这篇关于IndexOutOfBoundsException异常三星设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆