三星S4 OS 4.3上的Time Picker Dialog崩溃

时间:2014-02-24 10:35:26

标签: java android eclipse android-timepicker

每当我点击Timepicker时,我一直都会遇到这个问题。任何其他设备上都不会出现此问题,以下是错误日志:

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)

1 个答案:

答案 0 :(得分:1)

将此项添加到您想要触发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();