Активность календаря NullPointerException установка minDate и maxDate
Я получаю NullPointerException
когда я установил minDate
а также maxDate
в onCreate
из CalendarActivity
, Я отчаянно ищу решение.
Когда я комментирую minDate
а также maxDate
линий нет проблем.
Я вызываю Календарь с диапазоном дат (взятым с помощью AsyncTask через http POST), когда я изменяю этот диапазон и увеличиваю его, иногда проблем тоже нет.
Мой Логкат:
06-17 12:32:39.636 21968-21968/com.example.lissar W/EGL_genymotion﹕ eglSurfaceAttrib not implemented
06-17 12:32:39.660 21968-21968/com.example.lissar W/EGL_genymotion﹕ eglSurfaceAttrib not implemented
06-17 12:32:39.664 21968-21968/com.example.lissar D/AndroidRuntime﹕ Shutting down VM
06-17 12:32:39.664 21968-21968/com.example.lissar W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4c00648)
06-17 12:32:39.676 21968-21968/com.example.lissar E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at android.widget.CalendarView.onScroll(CalendarView.java:1214)
at android.widget.CalendarView.access$900(CalendarView.java:76)
at android.widget.CalendarView$2.onScroll(CalendarView.java:1075)
at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:1340)
at android.widget.ListView.layoutChildren(ListView.java:1762)
at android.widget.AbsListView.onLayout(AbsListView.java:2012)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1660)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Я вставляю код где minDate
а также maxDate
методы в. В конце onCreate
:
calendarView = (CalendarView) findViewById(R.id.calendarView1);
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
String yearFormat = "", monthFormat = "", dayFormat = "";
// El mes empieza en 0, así que aumentamos en uno para que cada mes coincida
// con su número correspondiente: enero -> 1, febrero -> 2, etc...
month += 1;
if (month < 10) {
monthFormat = String.format("%02d", month);
} else {
monthFormat = Integer.toString(month);
}
if (dayOfMonth < 10) {
dayFormat = String.format("%02d", dayOfMonth);
} else {
dayFormat = Integer.toString(dayOfMonth);
}
yearFormat = Integer.toString(year);
// Calculamos el día de la semana para mostrarlo en el Dialog
Calendar selected = Calendar.getInstance();
selected.setTimeInMillis(view.getDate());
int dayOfWeek = selected.get(Calendar.DAY_OF_WEEK);
HoursDialog hoursDialog = new HoursDialog(CalendarActivity.this,
yearFormat, monthFormat, dayFormat, dayOfWeek);
hoursDialog.show();
}
});
GregorianCalendar cal = new GregorianCalendar();
GregorianCalendar cal2 = new GregorianCalendar(); // Hoy
int daysBefore = daysEnabled * -1;
cal.add(GregorianCalendar.DATE, daysBefore);
calendarView.setMinDate(cal.getTime().getTime());
calendarView.setMaxDate(cal2.getTime().getTime());
Как я могу решить эту ошибку?
1 ответ
Я отвечаю сам.
- https://code.google.com/p/android/issues/detail?id=42750
- http://www.akikoskinen.info/how-to-use-androids-calendarview-widget/
В календарной активности есть некоторые ошибки. Я наконец использовал Caldroid: https://github.com/roomorama/Caldroid