I am getting error for second last bracket . I checked my code twice , all the opening and closing brackets are correct

I am trying to validate my register page but I am getting error for second last bracket . I checked my code twice , all the opening and closing brackets are correct . Still I am getting error for bracket .Also, even after putting correct name in name field its showing me error "ENTER ONLY ALPHABETICAL CHARACTER" . Any help is highly appreciated.

package com.example.kriova;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class signup_page extends AppCompatActivity {

    EditText name, email, phone, password, confirmpass;
    Button signup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signup_page);

        name = findViewById(R.id.name1);
        email = findViewById(R.id.email1);
        phone = findViewById(R.id.phone1);
        password = findViewById(R.id.password1);
        confirmpass = findViewById(R.id.confirmpassword1);
        signup = findViewById(R.id.signup);

        signup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String name1 = name.getText().toString();
                String email1 = email.getText().toString();
                String phone1 = phone.getText().toString();
                String password1 = password.getText().toString();
                String confirmpassword1 = confirmpass.getText().toString();

                //make function for validation and pass all parameters

                boolean check = validateinfo(name1, email1, phone1, password1, confirmpassword1);

                if (check == true) {
                    Toast.makeText(getApplicationContext(), "DATA IS VALID", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getApplicationContext(), "DATA IS INVALID", Toast.LENGTH_SHORT).show();
                }


            }
        });

    }

    private Boolean validateinfo(String name1, String email1, String phone1, String password1, String confirmpassword1) {
        if (name1.length() == 0) {
            name.requestFocus();
            name.setError("FIELD CANNOT BE EMPTY");
            return false;
        }
        else if (!name1.matches("[a-zA-Z]")) {
            name.requestFocus();
            name.setError("ENTER ONLY ALPHABETICAL CHARACTER");
            return false;
        }
        else if (email.length() == 0) {
            email.requestFocus();
            email.setError("FIELD CANNOT BE EMPTY");
            return false;
        }
        else if (!email1.matches("[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+")) {
            email.requestFocus();
            email.setError("ENTER VALID EMAIL");
            return false;
        }
        else if (phone1.length() == 0) {
            phone.requestFocus();
            phone.setError("FIELD CANNOT BE EMPTY");
            return false;
        }
        else if (!phone1.matches("^[+][0-9]{10,13}$")) {
            phone.requestFocus();
            phone.setError("CORRECT FORMAT IS: +91**********");
            return false;
        }
        else if (password1.length() <= 5) {
            password.requestFocus();
            password.setError("MINIMUM 6 CHARACTERS REQUIRED");
            return false;
        }
        else if (confirmpassword1.length() <= 5) {
            confirmpass.requestFocus();
            confirmpass.setError("MINIMUM 6 CHARACTERS REQUIRED");
            return false;
        }

    }

}

this is error I am getting

error: missing return statement
    }

>Solution :

        return false;
    }

}

insert return statement between the two brackets.

Leave a Reply