title: Datepicker in Class Activity
body: <p>I'm using the following code in the activity ApplyLeave. I would like to pick the date and save the date, month and year to public int variables.</p>
  <pre><code>            final Calendar calendar = Calendar.getInstance();
              DatePickerDialog dialog = new DatePickerDialog(ApplyLeave.this, new DatePickerDialog.OnDateSetListener() {
                  @Override
                  public void onDateSet(DatePicker arg0, int year, int month, int day_of_month) {
                      calendar.set(Calendar.YEAR, year);
                      calendar.set(Calendar.MONTH, (month)); //add +1 for next month calendar
                      calendar.set(Calendar.DAY_OF_MONTH, day_of_month);
                      String myFormat = &quot;dd/MM/yyyy&quot;;
                      SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.getDefault());
                      dtTmp = sdf.format(calendar.getTime());
  
                  }
              },calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
              dialog.getDatePicker().setMinDate(calendar.getTimeInMillis());//used to hide previous date,month and year
              calendar.add(Calendar.YEAR, 0);
              //dialog.getDatePicker().setMaxDate(calendar.getTimeInMillis());//used to hide future date,month and year
              dialog.show();
              String[] selTmp = dtTmp.split(&quot;/&quot;);
  
              selBdate = Integer.parseInt(selTmp[0]);
              selBmonth = Integer.parseInt(selTmp[1]);
              selByear = Integer.parseInt(selTmp[2]);
              stDt = MyUtility.getJulianDay(selByear, selBmonth, selBdate, ApplyLeave.this);
              eBegin.setText(dtTmp);
  </code></pre>
  <p>I get the error</p>
  <blockquote>
  <p>java.lang.NullPointerException: Attempt to invoke
  virtual method 'java.lang.String[]
  java.lang.String.split(java.lang.String)' on a null object reference
  at Line &quot;String[] selTmp = dtTmp.split(&quot;/&quot;);</p>
  </blockquote>
  <p>If I comment this line and the three following, the date gets picked up, but need to click twice to get the correct date set.</p>
  <p>The datepicker code is taken from <a href="https://stackoverflow.com/questions/16749361/how-set-maximum-date-in-datepicker-dialog-in-android/46441581?noredirect=1#comment112276801_46441581">Answer by @Sunil</a>.</p>