Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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
    }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

        return false;
    }

}

insert return statement between the two brackets.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading