I've written the below code to validate the worthiness within the string before saving it towards the database.

EditText editText2 = (EditText) this.findViewById(R.id.editText1);
           setTime = editText2.getText().toString(); 

           Log.d(setTime, "This is the setTime value");

           if(setTime == null)
           {
               Toast.makeText(Settings.this, "Time cannot be NULL", Toast.LENGTH_LONG).show(); 
           }

           else if(setTime != null)
           {
               cv.put(DatabaseHelper.TIME, setTime);
               db.insert("finalP", DatabaseHelper.TIME, cv);
               db.close();

               editText2.setText("");

               Toast.makeText(Settings.this, "Time saved", Toast.LENGTH_LONG).show();
           }

But even when "setTime" consists of the null value, the "if" part gets missed and also the control adopts the "else" part directly and saving the null value in database.

Is not this the right way to validate??

I believe you string is empty not null. So add look for string length too to if clause.

EditText editText2 = (EditText) this.findViewById(R.id.editText1);
setTime = editText2.getText().toString(); 

Log.d(setTime, "This is the setTime value");

if(setTime == null || setTime.length() == 0) {
   Toast.makeText(Settings.this, "Time cannot be NULL", Toast.LENGTH_LONG).show(); 
} else {
   cv.put(DatabaseHelper.TIME, setTime);
   db.insert("finalP", DatabaseHelper.TIME, cv);
   db.close();

   editText2.setText("");

   Toast.makeText(Settings.this, "Time saved", Toast.LENGTH_LONG).show();
}