Question

enter image description here

if((noValidate.getText().toString().length()>0)  &&     (nameValidate.getText().toString().length()>0)  &&
            (conpassValidate.getText().toString() ==  passValidate.getText().toString()) &&  (email.matches(emailPattern))
            &&(passValidate.getText().toString().length()>0))
        {
        Toast.makeText(this, "Your Information are saved succesfully ",   Toast.LENGTH_SHORT).show();

        Intent getStarted = new Intent(getApplicationContext(),  FourthActivity.class);
        startActivity(getStarted);
        }
    else
    {
        Toast.makeText(this, "Field Requiered",Toast.LENGTH_SHORT ).show();
    }
}

here when i click on the sign in button it will validate and summerise the field. If any field is empty it will show that field required. if i entered data in all field means it always shows that field required. I don't know where was the problem.

Was it helpful?

Solution

In Java, you cannot compare strings using an equal operator (=):

conpassValidate.getText().toString() ==  passValidate.getText().toString()

Use the equal method instead:

conpassValidate.getText().toString().equals(passValidate.getText().toString())

This would be the full code:

if((noValidate.getText().toString().length()>0)  &&     
   (nameValidate.getText().toString().length()>0)  &&
   (conpassValidate.getText().toString().equals(passValidate.getText().toString())) &&  
   (email.matches(emailPattern)) && 
   (passValidate.getText().toString().length()>0)) {

       Toast.makeText(this, "Your Information are saved succesfully ",   Toast.LENGTH_SHORT).show();
       Intent getStarted = new Intent(getApplicationContext(),  FourthActivity.class);
       startActivity(getStarted);
} else {
       Toast.makeText(this, "Field Requiered",Toast.LENGTH_SHORT ).show();
}

If this still does not work, print your validation using this code after else

String tag = "Your Tag";
Log.d(tag, "1: " + noValidate.getText().toString().length()>0 ? "YES":"NO");
Log.d(tag, "2: " + nameValidate.getText().toString().length()>0 ? "YES":"NO");
Log.d(tag, "3: " + conpassValidate.getText().toString().equals(passValidate.getText().toString()) ? "YES":"NO");
Log.d(tag, "4: " + email.matches(emailPattern) ? "YES":"NO");
Log.d(tag, "5: " + passValidate.getText().toString().length()>0 ? "YES":"NO");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top