title: Attempt to invoke virtual method 'long java.util.Date.getTime()'
body: <p>I'm new to android and I get a little bit confused on the java program. In my program, I have created 4 time picker which used to pick up time in and time out. After that, an editText will display the total hours. </p>
  
  <pre><code> SimpleDateFormat format = new SimpleDateFormat("HH:mm");
              Date dateb=null;
              Date datec=null;
              Date dateb1=null;
              Date datec1=null;
              Date dateb2=null;
              Date datec2=null;
              Date dateb3=null;
              Date datec3=null;
  
  
              try {
                      dateb = format.parse(b);
                      datec = format.parse(c);
                      long difference = datec.getTime() - dateb.getTime();
                      int minutes = (int) ((difference / (1000 * 60)) % 60);
                      int hours = (int) ((difference / (1000 * 60 * 60)) % 24) - 1;
                      editTextH1.setText((hours + ":" + minutes));
                  } catch (Exception e) {
  
                      System.err.println("ouch!");
                  }
                      try {
  
                           dateb1 = format.parse(d);
                           datec1 = format.parse(e1);
                          long difference1 = datec1.getTime() - dateb1.getTime();
                          int minutes1 = (int) ((difference1 / (1000 * 60)) % 60);
                          int hours1 = (int) ((difference1 / (1000 * 60 * 60)) % 24) - 1;
                          editTextH2.setText((hours1 + ":" + minutes1));
                      } catch (Exception e) {
  
                          System.err.println("ouch!");
                      }
              try {
  
                  dateb2 = format.parse(f);
                   datec2 = format.parse(g);
                  long difference2 = datec2.getTime() - dateb2.getTime();
                  int minutes2 = (int) ((difference2 / (1000 * 60)) % 60);
                  int hours2 = (int) ((difference2 / (1000 * 60 * 60)) % 24) - 1;
                  editTextH3.setText((hours2 + ":" + minutes2));
              } catch (Exception e) {
  
                  System.err.println("ouch!");
              }
              try {
                   dateb3 = format.parse(h);
                   datec3 = format.parse(i);
                  long difference3 = datec3.getTime() - dateb3.getTime();
                  int minutes3 = (int) ((difference3 / (1000 * 60)) % 60);
                  int hours3 = (int) ((difference3 / (1000 * 60 * 60)) % 24) - 1;
                  editTextH4.setText((hours3 + ":" + minutes3));
              }catch (Exception e) {
  
                  System.err.println("ouch!");
              }
  
  // display total hours 
                  long dateb_sum = dateb.getTime() + dateb1.getTime() + dateb2.getTime()+dateb3.getTime();
                  long datec_sum = datec.getTime() + datec1.getTime() + datec2.getTime()+datec3.getTime();
                  long difference4 = datec_sum - dateb_sum;
                  int minutes4 = (int) ((difference4/ (1000*60)) % 60);
                  int hours4  = (int) ((difference4/ (1000*60*60)) % 24)-1;
                  editText8.setText((hours4+":"+minutes4));
  
                  }
  
  
              }
  </code></pre>
  
  <p>When I run my app, it crashed on the time picker and the project forced to stop.I have initialized all my editText but still getting this error. Anyone can help me? Thanks</p>
  
  <p><strong>LogCat</strong></p>
  
  <pre><code> 10-01 01:21:13.041    4552-4552/com.example.project.project E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: com.example.project.project, PID: 4552
      java.lang.NullPointerException: Attempt to invoke virtual method 'long java.util.Date.getTime()' on a null object reference
              at com.example.project.project.WorkDetailsTable$TimePick.onTimeSet(WorkDetailsTable.java:381)
              at android.app.TimePickerDialog.onClick(TimePickerDialog.java:145)
              at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:163)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:148)
              at android.app.ActivityThread.main(ActivityThread.java:5417)
              at java.lang.reflect.Method.invoke(Native Method)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  </code></pre>
  
  <p>I'm pretty sure the error come from the coding below because it doesn't crashed when I remove them. But I need them to calculate the overall total hours!!</p>
  
  <pre><code>long dateb_sum = dateb.getTime() + dateb1.getTime() + dateb2.getTime()+dateb3.getTime();
                      long datec_sum = datec.getTime() + datec1.getTime() + datec2.getTime()+datec3.getTime();
                      long difference4 = datec_sum - dateb_sum;
                      int minutes4 = (int) ((difference4/ (1000*60)) % 60);
                      int hours4  = (int) ((difference4/ (1000*60*60)) % 24)-1;
                      editText8.setText((hours4+":"+minutes4));
  </code></pre>