title: Using DatePicker on custom dialog
body: <p>Well ,thats my code.I want to take values from a DatePicker from a custom Dialog. When i try to initialize dp (DatePicker) i got a nullPointerException error and i cant take the values from DatePicker to variables. :/ Anyone knows what is going on?  (I have 1 layouts. The main (R.layout.notifications) and the dialog layout (R.layout.notifications_dialog) the datepicker is on the notifications_dialog layout.</p>
  
  <pre><code>public class Notifications extends Activity {
  
  static final int CUSTOM_DIALOG_ID = 0;
  EditText Notification, Freq;
  Button Save, Cancel;
  int Year, Month , Day ;
  DatePicker dp;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.notifications); 
      Button ok = (Button) findViewById(R.id.ok);
      dp=(DatePicker)findViewById(R.id.notdate);
  
  
      ok.setOnClickListener(new OnClickListener() {                
               public void onClick(View ovuinfo) {
                  showDialog(CUSTOM_DIALOG_ID);                
                 }
             });
  }
  
  @Override
  protected Dialog onCreateDialog(int id) {
   Dialog dialog = null;;
      switch(id) {
      case CUSTOM_DIALOG_ID:
       dialog = new Dialog(Notifications.this);
  
       dialog.setContentView(R.layout.notifications_dialog);
       dialog.setTitle("Add Notification");
  
       Notification = (EditText)dialog.findViewById(R.id.notification);
       Freq = (EditText)dialog.findViewById(R.id.freq);
       Save = (Button)dialog.findViewById(R.id.add);
       Cancel = (Button)dialog.findViewById(R.id.canc);
       dp=(DatePicker)findViewById(R.id.notdate);
  
       final Calendar cal = Calendar.getInstance();
       int year = cal.get(Calendar.YEAR);
       int monthOfYear = cal.get(Calendar.MONTH);
       int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
  
        // here is the problem!
        dp.init(year, monthOfYear, dayOfMonth, new OnDateChangedListener() {
           @Override
           public void onDateChanged(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
               Year = year;
               Month = monthOfYear;
               Day = dayOfMonth;
           }
           });
  
       Save.setOnClickListener(SaveOnClickListener);
       Cancel.setOnClickListener(CancelOnClickListener);
          break;
      }
      return dialog;
  }  
  
   private Button.OnClickListener SaveOnClickListener = new Button.OnClickListener(){      
           @Override
           public void onClick(View arg0) {   
               String not = Notification.getText().toString();
               String fre = Freq.getText().toString();
  
               Toast toast = Toast.makeText(getApplicationContext(), not+":"+fre+":"+Day+"-"+Month+"-"+Year, Toast.LENGTH_SHORT);
                toast.show();
           }          
      };
  
      private Button.OnClickListener CancelOnClickListener = new Button.OnClickListener(){
           @Override
           public void onClick(View arg0) {
            dismissDialog(CUSTOM_DIALOG_ID);
           }
       };
  
  }
  </code></pre>