文本更改侦听器执行后的致命错误

时间:2011-09-21 12:22:04

标签: android

解决

我有一个应用程序,只要在EditText中更新搜索字符串,就会搜索arraylist。 我有一个文本更改侦听器添加到EditText。它通常可以工作,但随机我得到一个致命的错误,没有引用我的应用程序中的行号(我正在使用Eclipse Logcat) 我已将日志输出放在我的代码中以查找执行的最后一行。出乎意料的是,在文本更改侦听器执行了所有代码之后,这可能是在线程被传回UI之后? 我会感激任何帮助。

这是我的文本Listener中的完整代码。我得到了日志输出,说它完成了这个功能。那么线程在这之后会去哪里?

 public void afterTextChanged(Editable s) {
            if (("" + inputField.getText()).length() > 0) {
                fullSearchString += ("" + inputField.getText()).trim();
                inputField.setText("");
                searchArray(fullSearchString);
                out("FINISHED Text change Listener");
            }
        }

这是堆栈跟踪

09-21 13:05:24.146: ERROR/AndroidRuntime(7660): FATAL EXCEPTION: main
09-21 13:05:24.146: ERROR/AndroidRuntime(7660): java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at java.util.ArrayList.get(ArrayList.java:311)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at android.widget.TextView.sendAfterTextChanged(TextView.java:6194)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:6377)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at android.text.SpannableStringBuilder.sendTextHasChanged(SpannableStringBuilder.java:897)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:353)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:269)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:432)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:409)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:28)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:583)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:174)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:120)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:257)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:77)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at android.os.Looper.loop(Looper.java:123)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at java.lang.reflect.Method.invokeNative(Native Method)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at java.lang.reflect.Method.invoke(Method.java:521)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
09-21 13:05:24.146: ERROR/AndroidRuntime(7660):     at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案