title: Sqlite Database Date show in ListView
body: <p>MainActivity class.</p>
  
  <p>public class MainActivity extends Activity {</p>
  
  <pre><code>EditText etName, etEmail, etPhone, etDesignation;
  DatabaseHelper dbHelper;
  
  // declare view
  ListView lvEmployees;
  // declare adapter
  CustomizedAdapter adapter;
  Employee employee;
  
  // datasource
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      etName = (EditText) findViewById(R.id.etName);
      lvEmployees = (ListView) findViewById(R.id.lvEmployees);
      dbHelper = new DatabaseHelper(this);
      Employee employee;
  }
  
  public void save(View v) {
      String name = etName.getText().toString();
      SimpleDateFormat sm = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
      Date today = Calendar.getInstance().getTime();
      String reportDate = sm.format(today);
  
      Employee employee = new Employee(name, reportDate);
      Toast.makeText(getApplicationContext(), employee.toString(),
              Toast.LENGTH_LONG).show();
  
      long inserted = dbHelper.insertEmployee(employee);
      if (inserted &gt;= 0) {
          Toast.makeText(getApplicationContext(), "Data inserted",
                  Toast.LENGTH_LONG).show();
      } else {
          Toast.makeText(getApplicationContext(), "Data insertion failed...",
                  Toast.LENGTH_LONG).show();
      }
  
  }
  
  public void view(View v) {
      ArrayList&lt;Employee&gt; employees = dbHelper.getAllEmployees();
      if (employees != null &amp;&amp; employees.size() &gt; 0) {
          adapter = new CustomizedAdapter(this, employees);
          lvEmployees.setAdapter(adapter);
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is my DataBasehelper</p>
  
  <p>public class DatabaseHelper extends SQLiteOpenHelper {</p>
  
  <pre><code>public static final String DB_NAME = "task_management";
  public static final int DB_VERSION = 1;
  
  public static final String EMPLOYEE_TABLE = "employee";
  public static final String ID_FIELD = "_id";
  public static final String NAME_FIELD = "name";
  public static final String TIME_DATE = "time_date";
  
  public static final String EMPLOYEE_TABLE_SQL = "CREATE TABLE "
          + EMPLOYEE_TABLE + " (" + ID_FIELD + " INTEGER PRIMARY KEY, "
          + NAME_FIELD + " TEXT, " + TIME_DATE + " DATETIME);";
  
  public DatabaseHelper(Context context) {
      super(context, DB_NAME, null, DB_VERSION);
  
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {
      // create tables
      db.execSQL(EMPLOYEE_TABLE_SQL);
      Log.e("TABLE CREATE", EMPLOYEE_TABLE_SQL);
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      // upgrade logic
  
  }
  
  // insert
  public long insertEmployee(Employee emp) {
      SQLiteDatabase db = this.getWritableDatabase();
      ContentValues values = new ContentValues();
  
      values.put(NAME_FIELD, emp.getName());
      SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
      String date = sdf.format(emp.getDate());
      values.put(TIME_DATE, date);
      long inserted = db.insert(EMPLOYEE_TABLE, null, values);
  
      db.close();
      return inserted;
  }
  
  // query
  public ArrayList&lt;Employee&gt; getAllEmployees() {
      ArrayList&lt;Employee&gt; allEmployees = new ArrayList&lt;Employee&gt;();
      SQLiteDatabase db = this.getReadableDatabase();
  
      // String[] columns={NAME_FIELD, EMAIL_FIELD, PHONE_FIELD};
      // SELECT * FROM EMPLOYEE;
      Cursor cursor = db.query(EMPLOYEE_TABLE, null, null, null, null, null,
              null);
  
      // Cursor cursor = db.rawQuery("SELECT * FROM EMPLOYEE", null);
      if (cursor != null &amp;&amp; cursor.getCount() &gt; 0) {
          cursor.moveToFirst();
          for (int i = 0; i &lt; cursor.getCount(); i++) {
              //
              int id = cursor.getInt(cursor.getColumnIndex(ID_FIELD));
              String name = cursor.getString(cursor
                      .getColumnIndex(NAME_FIELD));
              String datetime = cursor.getString(cursor
                      .getColumnIndex(TIME_DATE));
              Employee e = new Employee(name, datetime);
              allEmployees.add(e);
              cursor.moveToNext();
          }
      }
      cursor.close();
      db.close();
  
      return allEmployees;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Custom Adapter..</p>
  
  <p>public class CustomizedAdapter extends ArrayAdapter {</p>
  
  <pre><code>Activity con;
  ArrayList&lt;Employee&gt; employeeList;
  Employee employee;
  
  public CustomizedAdapter(Context context, ArrayList&lt;Employee&gt; employees) {
      super(context, R.layout.list_item, employees);
      this.con = (Activity) context;
      this.employeeList = employees;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      View v = null;
      if (convertView == null) {
          // generate a view and return
          LayoutInflater inflater = con.getLayoutInflater();
          v = inflater.inflate(R.layout.list_item, null);
  
          TextView txtName = (TextView) v.findViewById(R.id.txtName);
          TextView datee = (TextView) v.findViewById(R.id.txtEmail);
          Employee e = employeeList.get(position);
          Date date = e.getDate();
          // Date date = e.get(position).getWishDate();
          datee.setText(DateFormat.format("dd/MM/yyyy hh:mm:ss a", date));
          txtName.setText(e.getName());
          datee.setText(e.getDatetime());
  
      } else {
          v = convertView;
      }
      return v;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here is LogCat:</p>
  
  <pre><code>09-27 16:11:35.374: E/AndroidRuntime(32300): FATAL EXCEPTION: main
  
  09-27 16:11:35.374: E/AndroidRuntime(32300): java.lang.IllegalStateException: Could not execute method of the activity
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at android.view.View$1.onClick(View.java:3609)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at android.view.View.performClick(View.java:4102)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at android.view.View$PerformClick.run(View.java:17085)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at android.os.Handler.handleCallback(Handler.java:615)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at android.os.Handler.dispatchMessage(Handler.java:92)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at android.os.Looper.loop(Looper.java:155)
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at 
  android.app.ActivityThread.main(ActivityThread.java:5511)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at java.lang.reflect.Method.invokeNative(Native Method)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at java.lang.reflect.Method.i
  nvoke(Method.java:511)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at dalvik.system.NativeStart.main(Native Method)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300): Caused by: java.lang.reflect.InvocationTargetException
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at java.lang.reflect.Method.invokeNative(Native Method)
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at java.lang.reflect.Method.invoke(Method.java:511)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at android.view.View$1.onClick(View.java:3604)
  09-27 16:11:35.374: E/AndroidRuntime(32300):    ... 11 more
  
  09-27 16:11:35.374: E/AndroidRuntime(32300): Caused by: java.lang.NullPointerException
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at java.util.Calendar.setTime(Calendar.java:1324)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at 
  java.text.SimpleDateFormat.formatImpl(SimpleDateFormat.java:536)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:821)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at java.text.DateFormat.format(DateFormat.java:376)
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at
  
  com.shikkhok.taskmanagement.DatabaseHelper.insertEmployee(DatabaseHelper.java:51)
  09-27 16:11:35.374: E/AndroidRuntime(32300):    at 
  
  com.shikkhok.taskmanagement.MainActivity.save(MainActivity.java:48)
  
  09-27 16:11:35.374: E/AndroidRuntime(32300):    ... 14 more
  
  09-27 16:11:35.394: E/EmbeddedLogger(426): App crashed! Process: com.shikkhok.taskmanagement
  
  09-27 16:11:35.394: E/EmbeddedLogger(426): App crashed! Package: com.shikkhok.taskmanagement v1 (1.0)
  
  09-27 16:11:35.394: E/EmbeddedLogger(426): Application Label: My Task Management
  
  09-27 16:11:36.124: E/Trace(32345): error opening trace file: No such file or directory (2)
  </code></pre>
  
  <p>I want to show my current time and date into my ListView and want to save it into database.
  I want to pick date and time and wants to save it as a String in my Sqlite database.
  When i want to save my date the apps turens to stop.
  So how to solve it??</p>