title: SQLite table returning Null Date
body: <p>I am working on an Android Activity that reads Date of Birth entered by the user and instantiates an object with the value. The date is then stored in an SQLite table. The problem is that I get a NULL date value when I query the table later for the Date.</p>
  
  <p>The date is being received correctly by the constructor of the object. However, it returns NULL when queried for it later.</p>
  
  <p>It will be great if you could point out the error.</p>
  
  <p><strong>Method that reads the Date, instantiates the object and stores in SQLite. The value is being read from EditText dob</strong></p>
  
  <pre><code>    b.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
  
              final EditText name = (EditText) findViewById(R.id.nameinput);
              final EditText dob = (EditText) findViewById(R.id.dobinput);
              final EditText mobile_no = (EditText) findViewById(R.id.mnuminput);
              final EditText alt_no = (EditText) findViewById(R.id.altnuminput);
              final EditText email_id = (EditText) findViewById(R.id.emailinput);
              final EditText home_adr = (EditText) findViewById(R.id.homeadrinput);
              final EditText off_adr = (EditText) findViewById(R.id.offadrinput);
              final EditText notes = (EditText) findViewById(R.id.notesinput);
              final TextView flag = (TextView) findViewById(R.id.insertflaglabel);
  
              String name_converted = name.getText().toString();
              String mobile_no_converted = mobile_no.getText().toString();
              String alt_no_converted = alt_no.getText().toString();
              String email_id_converted = email_id.getText().toString();
              String home_adr_converted = home_adr.getText().toString();
              String off_adr_converted = off_adr.getText().toString();
              String notes_converted = notes.getText().toString();
  
              DateFormat df = DateFormat.getDateInstance();
              Date dob_converted = new Date(DateFormat.MEDIUM);
  
              try {
                   dob_converted = df.parse(dob.getText().toString());
  
              } catch (ParseException e) {
                  e.printStackTrace();
              }
  
              Log.d("add_client", "Date read is " +dob_converted);
              client client_new = new client(name_converted, dob_converted, mobile_no_converted, alt_no_converted, home_adr_converted, off_adr_converted, email_id_converted, notes_converted);
  
              Context context = getBaseContext();
              database_handler insert_client = new database_handler(context);
              Log.d("add_client", "Date instantiated is " +client_new.getDOB());
              insert_client.addClient(client_new);
              flag.setText("Client Details Saved!");
          }
  
      });
  }
  </code></pre>
  
  <p><strong>Method that queries SQLite for Date of Birth using .getDOB()</strong></p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_display_clientdetails);
  
      Bundle extras = getIntent().getExtras();
      Integer tab_id = 0;
  
      if (extras != null) {
          tab_id = (int) extras.getInt("client_id");
      }
  
      TextView namev = (TextView) findViewById(R.id.namevalue);
      TextView mobnum = (TextView) findViewById(R.id.mnumvalue);
      TextView date_ob = (TextView) findViewById(R.id.dobvalue);
      TextView altnum = (TextView) findViewById(R.id.altnumvalue);
      TextView off_addr = (TextView) findViewById(R.id.offadrvalue);
      TextView home_addr = (TextView) findViewById(R.id.homeadrvalue);
      TextView email_addr = (TextView) findViewById(R.id.emailvalue);
      TextView notes_client = (TextView) findViewById(R.id.notesvalue);
  
      Context c_displayclient = getBaseContext();
      database_handler dhandle = new database_handler(c_displayclient);
  
      String TAG = "display_clientdetails";
  
      Log.d(TAG, "Value of ID is " +tab_id);
      final client c_details = dhandle.getClient(tab_id);
      namev.setText(c_details.getName());
      mobnum.setText(c_details.getMobile_number());
      altnum.setText(c_details.getAlt_num());
  
  
      DateFormat datef = DateFormat.getDateInstance(DateFormat.MEDIUM);
  
      Log.d("display_clientdetails", "Date of Birth is " +c_details.getDOB());
  
  
      String text_date = datef.format(c_details.getDOB());
      date_ob.setText(text_date);
  </code></pre>
  
  <p><strong>Instantiation Code</strong></p>
  
  <pre><code>    // constructor
      public client(String name,Date dob,String mobile_number,String alternate_number,String office_address, String home_address,String email_id,String notes)
      {
  
          this.name = name;
          this.dob=dob;
          Log.d("client", "dob received in client constructor is " +this.dob);
          this.mobile_number = mobile_number;
          this.alternate_number=alternate_number;
          this.office_address=office_address;
          this.home_address=home_address;
          this.email_id=email_id;
          this.notes=notes;
      }
  </code></pre>
  
  <p><strong>Method that returns the Date of Birth</strong></p>
  
  <pre><code>    // getting Date of Birth
      public Date getDOB(){
          Log.d("client", "Date returned is " +this.dob);
          return this.dob;
  
      }
  </code></pre>
  
  <p><strong>Method that Adds a new entry to the Database Table</strong></p>
  
  <pre><code>  public void addClient(client client_instance) {
      SQLiteDatabase db = this.getWritableDatabase();
  
      ContentValues values = new ContentValues();
      values.put(KEY_NAME, client_instance.getName()); // Client Name
      values.put(KEY_MO_NO, client_instance.getMobile_number()); // Client Phone
      values.put(KEY_DOB, client_instance.getDOB().toString());
      values.put(KEY_ALT_NO,  client_instance.getAlt_num());
      values.put(KEY_OFF_ADR, client_instance.getOff_adr());
      values.put(KEY_HOM_ADR, client_instance.getHome_adr());
      values.put(KEY_EMAIL, client_instance.getEmail());
      values.put(KEY_NOTES, client_instance.getNotes());
  
      db.insert(TABLE_CLIENTS, null, values);
      db.close(); // Closing database connection
  
      }
  </code></pre>
  
  <p><strong>Method for Getting Data from the Database</strong></p>
  
  <pre><code> // Getting single contact
    client getClient(int id) {
      SQLiteDatabase db = this.getReadableDatabase();
      client client_instance = new client();
      String TAG ="database_handler";
  
      Cursor cursor = db.query(TABLE_CLIENTS, new String[] {
                      KEY_NAME, KEY_MO_NO, KEY_DOB, KEY_ALT_NO, KEY_OFF_ADR, KEY_HOM_ADR, KEY_EMAIL, KEY_NOTES}, KEY_ID + "=?",
              new String[] { String.valueOf(id) }, null, null, null, null);
  
  
      if(cursor != null) Log.d(TAG, "cursor is not null");
     // if(cursor.moveToFirst()) Log.d(TAG, "move to first is true");
  
      if (cursor != null &amp;&amp; cursor.moveToFirst()) {
  
          client_instance.setName(cursor.getString(0));
          client_instance.setMobileNumber(cursor.getString(1));
  
          //Convert Datefield from String to Date so that the setDOB method can accept it as argument
  
          DateFormat dateform = DateFormat.getDateInstance(DateFormat.FULL);
          Date d_of_b = new Date(DateFormat.FULL);
  
          try {
              d_of_b = dateform.parse(cursor.getString(2));
  
          } catch (ParseException e) {
              e.printStackTrace();
          }
  
          //Set Date of Birth
          client_instance.setDOB(d_of_b);
  
          client_instance.setAlt_num(cursor.getString(3));
          client_instance.setOff_adr(cursor.getString(4));
          client_instance.setHome_adr(cursor.getString(5));
          client_instance.setEmail(cursor.getString(6));
          client_instance.setNotes(cursor.getString(7));
          Log.d(TAG, "Email is " +cursor.getString(3));
          cursor.close();
      }
  
      return client_instance;
  
  }
  </code></pre>
  
  <p><strong>Method for Setting the Date of Birth into a new Client Instance</strong></p>
  
  <pre><code>   public void setDOB(Date dob){
      this.dob = dob;
     }
  </code></pre>