Why do I get a NPE (return dialog is null) with the following?
public class ViewCalendar extends DialogFragment implements OnDateSetListener {
private Calendar c = Calendar.getInstance();
private DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return dialog;
}
}
The following does work. Why?
public class ViewCalendar extends DialogFragment implements OnDateSetListener {
private Calendar c = Calendar.getInstance();
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
return dialog;
}
}