Ad

Why Are My Email And Password Variables Coming Up As Unresolved References?

I am using kotlin to build a basic an account creation form through firebase, and for some reason my variables are not being recognized and I define them right before the portion they are used in. Any help would be appreciated, code is below

class LoginActivity: AppCompatActivity() {

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

        setContentView(R.layout.activity_login)

        login_btn.setOnClickListener {
            val email = email_edittext.text.toString()
            val password = password_edittext.text.toString()

            Log.d("Login", "Attempt login with email/pw $email/***")
        }
        FirebaseAuth.getInstance().signInWithEmailAndPassword(email, password)
            .addOnCompleteListener()


        back_textview.setOnClickListener{
            finish()
        }
    }
}
Ad

Answer

Your variables are scoped to the lambda, so not visible outside it. Looks like you should be calling the signIn API within the lambda as well

login_btn.setOnClickListener {
    val email = email_edittext.text.toString()
    val password = password_edittext.text.toString()

    Log.d("Login", "Attempt login with email/pw $email/***")
    FirebaseAuth.getInstance().signInWithEmailAndPassword(email, password)
    .addOnCompleteListener()

}
Ad
source: stackoverflow.com
Ad