title: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'long java.util.Date.getTime()' on a null object reference in Android
body: <p>I want to convert <strong>strSqliteDate﹕ = 2016-01-14 05:34:50 PM</strong>  into <strong>2016-01-14</strong> .After converting all dates my application was crash and getting error of</p>
  
  <pre><code>02-01 12:03:15.204    7619-7619/com.example.tazeen.classnkk W/System.err﹕ java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
  02-01 12:03:15.204    7619-7619/com.example.tazeen.classnkk W/System.err﹕ at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1035)
  02-01 12:03:15.204    7619-7619/com.example.tazeen.classnkk W/System.err﹕ at java.text.DateFormat.parse(DateFormat.java:577)
  </code></pre>
  
  <p>At this line   <code>date = dateFormat.parse(strSqliteDate);</code></p>
  
  <p>and second getting error at this <code>line = calendar.setTime(date);</code></p>
  
  <blockquote>
    <p>Caused by: java.lang.NullPointerException: Attempt to invoke virtual
    method 'long java.util.Date.getTime()' on a null object reference
                at java.util.Calendar.setTime(Calendar.java:1195)</p>
  </blockquote>
  
  <p>Here is date conversion code in DBhelper class</p>
  
  <pre><code>String strSqliteDate = cursor.getString(cursor.getColumnIndex("ActionDate"));
                  Log.e(" strSqliteDate "," = " + strSqliteDate);
  
                  String result = "";
                  Date date = null;
                  DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                  try
                  {
                       date = dateFormat.parse(strSqliteDate);
                  }
                  catch(Exception e)
                  {
                      e.printStackTrace();
                  }
                  Calendar calendar = Calendar.getInstance();
                  calendar.setTime(date);
                  SimpleDateFormat printFormat = new SimpleDateFormat("yyyy-MM-dd");
                  result = printFormat.format(calendar.getTime());
                  Log.e("result = ","==========&gt;"+result);
  </code></pre>