每当我单击“时间选择器”时,我都会不断遇到此问题。在任何其他设备上都没有发生此问题,以下是错误日志:
Error log:
java.lang.NullPointerException
at android.widget.TimePicker.updateInputState(TimePicker.java:846)
at android.widget.TimePicker.onSaveInstanceState(TimePicker.java:561)
at android.view.View.dispatchSaveInstanceState(View.java:13117)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2822)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2828)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2828)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2828)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2828)
at android.view.View.saveHierarchyState(View.java:13100)
at com.android.internal.policy.impl.PhoneWindow.saveHierarchyState(PhoneWindow.java:1930)
at android.app.Dialog.onSaveInstanceState(Dialog.java:407)
at android.app.TimePickerDialog.onSaveInstanceState(TimePickerDialog.java:216)
at android.app.Activity.saveManagedDialogs(Activity.java:1269)
at android.app.Activity.performSaveInstanceState(Activity.java:1187)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1240)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3309)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3369)
at android.app.ActivityThread.access$1000(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1338)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)
最佳答案
将此添加到要触发TimePicker的位置::>
int hour,minute;
TimePickerDialog mTimePicker = new TimePickerDialog(mContext,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker,int selectedHour, int selectedMinute) {
hour = selectedHour;
minute = selectedMinute;
}
}, hour, minute, false);// Yes 24 hour time
mTimePicker.setTitle("Select Time");
hour = c.get(Calendar.HOUR);
minute = c.get(Calendar.MINUTE);
mTimePicker.updateTime(hour, minute);
mTimePicker.show();