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] = mCalendar.get(Calendar.MONTH); // zero based
mToday[2] = mCalendar.get(Calendar.YEAR);
Can not run my project because AndroidStudio shows error on the Calendar.DAY_OF_MONTH
, Calendar.MONTH
etc... I get nullPointException while running in emulator
It sais that
Must be one of: java.util.Calendar.DAY_OF_MONTHjava.util.Calendar.MONTH etc...
I don't understand this error because Calendar.MONTH
is one of java.util.calendar.MONTH
I have an import for it
import java.util.Calendar;
Sorry I missed that it's initialized but there is an other class where I want to use Calendar.MONTH and so on like this:
mCalendarToday = Calendar.getInstance();
...
int dayOfWeek = mCalendar.get(Calendar.DAY_OF_WEEK);
int firstDay = getDay(mCalendar.get(Calendar.DAY_OF_WEEK);
OR
private Calendar mCalendarToday;
...
private boolean isToday(int day, int month, int year) {
if (mCalendarToday.get(Calendar.MONTH) == month
&& mCalendarToday.get(Calendar.YEAR) == year
&& mCalendarToday.get(Calendar.DAY_OF_MONTH) == day) {
return true;
}
return false;
}
Here shows error too. And all the other lines where I would use.