我有一个日期选择器对话框,如果我一起设置MAX日期和最小日期,应用程序崩溃。然而,如果我只设置最小日期或最大日期它工作正常..帮我找出我出错的地方。
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)
答案 0 :(得分:2)
我和你有同样的问题。在我的应用程序中,我有一个扩展DatePickerDialog的片段,并在单击按钮时显示它。应用程序在大屏幕上崩溃,有足够的空间显示日期选择器的日历视图。但是,对于我的应用程序,不需要日历视图,并且通过禁用它,在设置最小和最大日期时应用程序不会再崩溃。
因此,如果您的应用程序也是如此,您不需要日历视图,请尝试通过在日期选择器实例上调用setCalendarViewShown(false)来禁用它。