The email address is badly formatted (Kotlin register button error)

Viewed 49

When I click the register button, it does not save the data and gives the following error;

com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The email address is badly formatted

Please help us find the error!

Register code page;

class RegisterActivity : AppCompatActivity() {
    private lateinit var binding : ActivityRegisterBinding
    private lateinit var firebaseAuth: FirebaseAuth

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityRegisterBinding.inflate(layoutInflater)
        setContentView(binding.root)

        firebaseAuth = FirebaseAuth.getInstance()
        binding.registerButton.setOnClickListener {
            val email = binding.yourEmail.text.toString()
            val pass = binding.editTextTextPassword2.text.toString()
            val username = binding.editTextTextPersonName.text.toString()

            if(email.isNotEmpty() && pass.isNotEmpty() && username.isNotEmpty()){

                firebaseAuth.createUserWithEmailAndPassword(email , pass).addOnCompleteListener{
                    if (it.isSuccessful){
                        val intent = Intent(this, LoginActivity::class.java)
                        startActivity(intent)
                    }else{
                        Toast.makeText(this,it.exception.toString(), Toast.LENGTH_LONG).show()
                    }
                }

            }else{
                Toast.makeText(this,"Empty Fields Are not Allowed !!", Toast.LENGTH_LONG).show()
            }
        }

        val loginresetActivity = findViewById<TextView>(R.id.textView6)
        textView6.setOnClickListener {
            val Intent = Intent(this, LoginActivity::class.java)
            startActivity(Intent)
        }
    }
}
1 Answers

I don't know if this will help but Make sure the string doesn't have white spaces im both sides (left and right)

val email = binding.yourEmail.text.toString().trim()
       
Related