我使用带有 Android 4.3 的三星 Galaxy S4。
我使用TimePickerDialog
我这样创建的:
new TimePickerDialog(this, mTimeSetListener, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true);
这是听众:
private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
if(isStartTimeModified){
updateStartTimeDisplay(hourOfDay, minute);
isStartTimeModified = false;
}else if(isEndTimeModified){
updateEndTimeDisplay(hourOfDay, minute);
isEndTimeModified = false;
}
}
};
一切都像魅力一样运作,直到我离开活动。然后我得到以下信息NullPointerException
:
E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at android.widget.TimePicker.onSaveInstanceState(TimePicker.java:470)
at android.view.View.dispatchSaveInstanceState(View.java:12623)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2671)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2677)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2677)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2677)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2677)
at android.view.View.saveHierarchyState(View.java:12606)
at com.android.internal.policy.impl.PhoneWindow.saveHierarchyState(PhoneWindow.java:1852)
at android.app.Dialog.onSaveInstanceState(Dialog.java:402)
at android.app.TimePickerDialog.onSaveInstanceState(TimePickerDialog.java:216)
at android.app.Activity.saveManagedDialogs(Activity.java:1264)
at android.app.Activity.performSaveInstanceState(Activity.java:1182)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1233)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3216)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3275)
at android.app.ActivityThread.access$1000(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5279)
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)
我发现了一些其他类似这样或这样的帖子,告诉我一个 Android 错误。
但仍然:我该怎么办?我需要时间选择器,这NPE
是不可接受的,对吧?
提前致谢,
罗恩
更新
在第 470 行,我在来源中找到了这个:
mHourSpinner.setValue(currentHour);
if (notifyTimeChanged) { //line 470
onTimeChanged();
}
但是这些是SDK19的来源,我的手机使用的是三星品牌的Android 4.3...