我试图设置一个侦听器来检测我的mAttendeesList中的文本是否已使用以下内容更改:
EditEventView.mAttendeesList.addTextChangedListener(mViewListener);
然而,mAttendeesList不断等于null ...
我已按如下方式实施:
private void initChangeListeners() {
if (mViewListener == null) {
mViewListener = new RecipientTextWatcher(mView, mViewListener);
}
EditEventView.mAttendeesList.addTextChangedListener(mViewListener);
}
...
static MultiAutoCompleteTextView mAttendeesList;
...
private boolean fillModelFromUI() {
...
if (mAttendeesList != null) {
...
但是它总是返回null,我不确定为什么。
非常感谢任何建议/指示。
private void initChangeListeners() {
clearChangeListeners();
if (mViewListener == null) {
mViewListener = new RecipientTextWatcher(mAttendeesList, mViewListener);
}
EditEventView mEditEventView = new EditEventView(EditEventActivity.this, mAttendeesList, mDone, false, false);
EditEventView.mAttendeesList.addTextChangedListener(mViewListener);
}
private void clearChangeListeners() {
if (mViewListener != null) {
mView.removeTextChangedListener(mViewListener);
}
}
错误:
FATAL EXCEPTION: main
Caused by: java.lang.NullPointerException
01-28 17:37:17.887: E/AndroidRuntime(16938): at com.android.calendar.event.EditEventView.<init>(EditEventView.java:851)
01-28 17:37:17.887: E/AndroidRuntime(16938): at com.android.calendar.event.EditEventActivity.initChangeListeners(EditEventActivity.java:183)
01-28 17:37:17.887: E/AndroidRuntime(16938): at com.android.calendar.event.EditEventActivity.onCreate(EditEventActivity.java:161)
错误发生在:
EditEventView 851: mAttendeesListView = (LinearLayout) view.findViewById(R.id.scheduling_attendee_list);
EditEventActivity 183: EditEventView mEditEventView = new EditEventView(EditEventActivity.this, mAttendeesList, mDone, false, false);
EditEventActivity 161: initChangeListeners();
https://www.zerobin.net/?2ce740738b028ed1#Q7JVl/DQXkMGqbYaYQ/XnXMX8pHLL3kbKHunLmkffqc=
答案 0 :(得分:2)
您从未初始化EditEventView
对象,并且您的mAttendeesList
已在其构造函数中初始化。因此,如果您未初始化EditEventView
(即调用其构造函数),则mAttendeesList
将为null。
在引用EditEventView.mAttendeesList
(或EditEventView
的任何动态成员)之前,您需要确保创建EditEventView
类的实例。