Friday, February 4, 2011

[android-developers] Problem with addTextChangedListener(new TextWatcher()

Hi,
What is wrong with my addTextChangedListener() implementation?
Something wrong with adapter.getFilter().filter(s)?
It crash with this statement, if I remark it then it will not crash
but the filter won't work of cause.

Many thanks.

---
searchbar = (EditText)findViewById(R.id.searchbar);
searchbar.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub

}

@Override
public void beforeTextChanged(CharSequence s, int start, int
count,
int after) {
// TODO Auto-generated method stub

}

@Override
public void onTextChanged(CharSequence s, int start, int
before,
int count) {
// TODO Auto-generated method stub
adapter.getFilter().filter(s);
adapter.notifyDataSetChanged();
}
});

---
02-05 03:46:17.212: ERROR/AndroidRuntime(862): FATAL EXCEPTION: main
02-05 03:46:17.212: ERROR/AndroidRuntime(862):
java.lang.NullPointerException
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
android.widget.SimpleAdapter.getCount(SimpleAdapter.java:93)
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
android.widget.AdapterView.checkFocus(AdapterView.java:689)
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
android.widget.AdapterView
$AdapterDataSetObserver.onInvalidated(AdapterView.java:813)
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
android.database.DataSetObservable.notifyInvalidated(DataSetObservable.java:
43)
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
android.widget.BaseAdapter.notifyDataSetInvalidated(BaseAdapter.java:
54)
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
android.widget.SimpleAdapter
$SimpleFilter.publishResults(SimpleAdapter.java:383)
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
android.widget.Filter$ResultsHandler.handleMessage(Filter.java:282)
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
android.os.Handler.dispatchMessage(Handler.java:99)
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
android.os.Looper.loop(Looper.java:123)
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
android.app.ActivityThread.main(ActivityThread.java:4627)
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
java.lang.reflect.Method.invokeNative(Native Method)
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
java.lang.reflect.Method.invoke(Method.java:521)
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-05 03:46:17.212: ERROR/AndroidRuntime(862): at
dalvik.system.NativeStart.main(Native Method)

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate