我正在尝试TextWatcher
在EditText
. 我EditText
在我的应用程序中使用了一个并通过TextWatcher
.
当我在栏中键入像“a”这样的字母时,EditText
我的光标可以工作,但是当我写下一个像“ab *”这样的字母时,光标根本不起作用,并且在删除这些字母时发生错误并且我的应用程序崩溃。我无法弄清楚我错过了什么。
这是我的代码:
TextWatcher myTextWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if (start == 0) {
SearchWordString.clear();
Cursor cursor = managedQuery(DictionaryProvider.CONTENT_URI, null, null,
new String[] {(search.getText().toString())}, null);
while(cursor.isAfterLast()==false)
{
SearchWordString.add(cursor.getString(1));
cursor.moveToNext();
}
listAdapter.notifyDataSetChanged();
viewFlipper.showNext();
} else {
}
listAdapter.notifyDataSetChanged();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
};
这是我的 LogCAT
01-15 04:54:25.080: W/dalvikvm(29324): threadid=1: thread exiting with uncaught exception (group=0x40b811f8)
01-15 04:54:25.103: E/AndroidRuntime(29324): FATAL EXCEPTION: main
01-15 04:54:25.103: E/AndroidRuntime(29324): java.lang.NullPointerException
01-15 04:54:25.103: E/AndroidRuntime(29324): at com.ilmasoft.GPD.Start$2.onTextChanged(Start.java:1432)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.widget.TextView.sendOnTextChanged(TextView.java:8085)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.widget.TextView.handleTextChanged(TextView.java:8132)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:8495)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.text.SpannableStringBuilder.sendTextChange(SpannableStringBuilder.java:892)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:389)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:266)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:443)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:216)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:29)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.text.method.BaseKeyListener.backspaceOrForwardDelete(BaseKeyListener.java:90)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.text.method.BaseKeyListener.backspace(BaseKeyListener.java:45)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.text.method.BaseKeyListener.onKeyDown(BaseKeyListener.java:151)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.text.method.QwertyKeyListener.onKeyDown(QwertyKeyListener.java:352)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.text.method.TextKeyListener.onKeyDown(TextKeyListener.java:132)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.widget.TextView.doKeyDown(TextView.java:5716)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.widget.TextView.onKeyDown(TextView.java:5531)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.view.KeyEvent.dispatch(KeyEvent.java:2608)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.view.View.dispatchKeyEvent(View.java:5547)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)
01-15 04:54:25.103: E/AndroidRuntime(29324): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2021)
01-15 04:54:25.103: E/AndroidRuntime(29324): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1382)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.app.Activity.dispatchKeyEvent(Activity.java:2324)
01-15 04:54:25.103: E/AndroidRuntime(29324): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1948)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3360)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2618)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.os.Looper.loop(Looper.java:137)
01-15 04:54:25.103: E/AndroidRuntime(29324): at android.app.ActivityThread.main(ActivityThread.java:4511)
01-15 04:54:25.103: E/AndroidRuntime(29324): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 04:54:25.103: E/AndroidRuntime(29324): at java.lang.reflect.Method.invoke(Method.java:511)
01-15 04:54:25.103: E/AndroidRuntime(29324): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
01-15 04:54:25.103: E/AndroidRuntime(29324): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
01-15 04:54:25.103: E/AndroidRuntime(29324): at dalvik.system.NativeStart.main(Native Method)