I have a problem with my calendar. Here is the code:
Calendar mCalendar = Calendar.getInstance();
mToday[0] = mCalendar.get(Calendar.DAY_OF_MONTH);
mToday[1]
It looks like a bug of Android Studio: 0.5.5
see http://code.google.com/p/android/issues/detail?id=68758
Hardcoded. But must work.
int[] mToday = new int[]{};
java.util.Calendar calendar = java.util.Calendar.getInstance();
mToday[0] = calendar.get(java.util.Calendar.DAY_OF_MONTH);
mToday[1] = calendar.get(java.util.Calendar.MONTH);
mToday[2] = calendar.get(java.util.Calendar.YEAR);
I do believe that the way you access the calendar is correct.
I'm guessing the int[]
you try to add the values to is not initialized.
You must call
int[] mToday = new int[3];
maybe you did not initialize you field. I tried it in Eclipse and this worked
int[] mToday = new int[10];
Calendar mCalendar = Calendar.getInstance();
mToday[0] = mCalendar.get(Calendar.DAY_OF_MONTH);
mToday[1] = mCalendar.get(Calendar.MONTH); // zero based
mToday[2] = mCalendar.get(Calendar.YEAR);