1

我有一个日期选择器对话框,如果我将 MAX date 和 Min date 一起设置,则应用程序崩溃。而如果我只设置最小日期或最大日期它工作正常.. 帮助我找出我哪里出错了。

   private void setDate(View c_c) {
    // TODO Auto-generated method stub

    final Dialog dialog = new Dialog(getParent());
    dialog.setContentView(R.layout.date_picker);
    dialog.setTitle("Select Date");
    DatePicker calendarView = (DatePicker) dialog.findViewById(R.id.date_picker_datepicker);

    try {
        Log.d("***ENC_dATE****",Utility.getCurrentDate()+"*******"+Utility.convertStringToMilli(Utility.getCurrentDate()));
        calendarView.setMinDate(Utility.convertStringToMilli(Utility.convertStringFormat(CommonObjects.patientsDtoEncounter.getEpisodeDate())));
        calendarView.setMaxDate(Utility.convertStringToMilli(Utility.getCurrentDate()));
    } catch (Exception e) {
        e.printStackTrace();
    }
    Button button = (Button) dialog.findViewById(R.id.btn_cancel_datepicker);

    button.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            dialog.dismiss();
        }


    });

    button = (Button) dialog.findViewById(R.id.btn_set_datepicker);
    button.setTag(c_c);

    // if button is clicked, close the custom dialog
    button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            dialog.dismiss();
        }
    });

    dialog.show();

}

这是我的日志。

08-26 11:31:26.127: D/***ENC_dATE****(1763): 26-Aug-13*******1377455400000
08-26 11:31:26.427: D/AndroidRuntime(1763): Shutting down VM
08-26 11:31:26.427: W/dalvikvm(1763): threadid=1: thread exiting with uncaught      exception (group=0x40a13300)
08-26 11:31:26.589: E/AndroidRuntime(1763): FATAL EXCEPTION: main
08-26 11:31:26.589: E/AndroidRuntime(1763): java.lang.NullPointerException
08-26 11:31:26.589: E/AndroidRuntime(1763):     at   android.widget.CalendarView.onScroll(CalendaView.java:1214)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at  android.widget.CalendarView.access$900(CalendarView.java:76)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.CalendarView$2.onScroll(CalendarView.java:1075)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:1326)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.ListView.layoutChildren(ListView.java:1707)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.AbsListView.onLayout(AbsListView.java:2106)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.View.layout(View.java:13754)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.ViewGroup.layout(ViewGroup.java:4364)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.View.layout(View.java:13754)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.ViewGroup.layout(ViewGroup.java:4364)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.View.layout(View.java:13754)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at    a ndroid.view.ViewGroup.layout(ViewGroup.java:4364)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at    android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1638)
 08-26 11:31:26.589: E/AndroidRuntime(1763):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1422)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.View.layout(View.java:13754)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.ViewGroup.layout(ViewGroup.java:4364)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.View.layout(View.java:13754)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.ViewGroup.layout(ViewGroup.java:4364)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.View.layout(View.java:13754)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.ViewGroup.layout(ViewGroup.java:4364)
 08-26 11:31:26.589: E/AndroidRuntime(1763):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at    android.view.View.layout(View.java:13754)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.ViewGroup.layout(ViewGroup.java:4364)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.View.layout(View.java:13754)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.ViewGroup.layout(ViewGroup.java:4364)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at a  ndroid.widget.LinearLayout.onLayout(LinearLayout.java:1420)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.View.layout(View.java:13754)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.ViewGroup.layout(ViewGroup.java:4364)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.View.layout(View.java:13754)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.ViewGroup.layout(ViewGroup.java:4364)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1868)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1689)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.Choreographer.doCallbacks(Choreographer.java:555)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.Choreographer.doFrame(Choreographer.java:525)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.os.Handler.handleCallback(Handler.java:615)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.os.Looper.loop(Looper.java:137)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at android.app.ActivityThread.main(ActivityThread.java:4745)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at java.lang.reflect.Method.invokeNative(Native Method)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at java.lang.reflect.Method.invoke(Method.java:511)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-26 11:31:26.589: E/AndroidRuntime(1763):     at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

2

我和你有同样的问题。在我的应用程序中,我有一个扩展 DatePickerDialog 并在单击按钮时显示它的片段。该应用程序在有足够空间显示日期选择器的日历视图的较大屏幕上崩溃。但是,对于我的应用程序,不需要日历视图,并且通过禁用它,应用程序在设置最小和最大日期时不再崩溃。

因此,如果您的应用程序也是这种情况,您不需要日历视图,请尝试通过在日期选择器实例上调用 setCalendarViewShown(false) 来禁用它。

于 2013-11-27T13:48:42.153 回答