强制关闭onTextChanged

时间:2013-12-03 14:07:23

标签: java android android-edittext

我得到一个力量关闭,但仅在某些情况下和某些设备中,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

有帮助吗?

2 个答案:

答案 0 :(得分:2)

试试这个

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);
    }
}

答案 1 :(得分:0)

试试这个,

 public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
               if(inputSearch.getText().toString()!=null && !inputSearch.getText().toString().equals(""))
               {
                String text =inputSearch.getText().toString().toLowerCase(Locale.getDefault());
                listadaptor.filter(text);
               }
            }