我得到了强制关闭,但仅在某些情况下和在某些设备上是onTextChanged。这是我写的:
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
String text =inputSearch.getText().toString().toLowerCase(Locale.getDefault());
listadaptor.filter(text);
}
logCat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dd.androreboot/com.dd.androreboot.applist}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2247)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2297)
at android.app.ActivityThread.access$700(ActivityThread.java:152)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5328)
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)
Caused by: java.lang.NullPointerException
at com.dd.androreboot.applist$3.onTextChanged(applist.java:104)
at android.widget.TextView.sendOnTextChanged(TextView.java:7822)
at android.widget.TextView.setText(TextView.java:4035)
at android.widget.TextView.setText(TextView.java:3890)
at android.widget.EditText.setText(EditText.java:100)
at android.widget.TextView.setText(TextView.java:3865)
at android.widget.TextView.onRestoreInstanceState(TextView.java:3758)
at android.view.View.dispatchRestoreInstanceState(View.java:12561)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2684)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2684)
at android.view.View.restoreHierarchyState(View.java:12539)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1845)
at android.app.Activity.onRestoreInstanceState(Activity.java:972)
at android.app.ListActivity.onRestoreInstanceState(ListActivity.java:219)
at android.app.Activity.performRestoreInstanceState(Activity.java:944)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1148)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225)
... 11 more
有帮助吗?
最佳答案
尝试这个
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
String text = inputSearch.getText().toString();
if(!text.equals("")){
text = text.toLowerCase(Locale.getDefault());
listadaptor.filter(text);
}
}
关于java - 强制关闭onTextChanged,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20353335/