-1
I’m following a tutorial I saw on Youtube but mine did not work... Elpe me Please....
By Debug I saw that the error starts inside the private fun functions creatOrLoginUser: I need to create a screen to register in firebase and login, and then authentication with google and facebook, but I can not even pass this part, I am new in programming and choose to start by Kotlin because I found it simpler than java... someone can help me in this?
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.os.Build
import android.view.View
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import com.github.dhaval2404.imagepicker.ImagePicker
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.UserProfileChangeRequest
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.tasks.await
import kotlinx.coroutines.withContext
class telaLogin : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
private var firstTimeUser= true
private var fileUri: Uri? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
auth = FirebaseAuth.getInstance()
buttonClicks()
}
private fun buttonClicks(){
btn_login.setOnClickListener{
firstTimeUser = false
creatOrLoginUser()
}
btn_register.setOnClickListener {
creatOrLoginUser()
}
iv_profileImage.setOnClickListener{
selectImage()
}
}
private fun creatOrLoginUser(){
val email = et_emailLogin.text.toString()
val password = et_passwordLogin.text.toString()
if(email.isNotEmpty() && password.isNotEmpty()){
GlobalScope.launch(Dispatchers.IO){
try {
if(firstTimeUser){
auth.createUserWithEmailAndPassword(email,password).await()
auth.currentUser.let {
val update = UserProfileChangeRequest.Builder().setPhotoUri(fileUri).build()
it?.updateProfile(update)
}?.await()
} else{
auth.signInWithEmailAndPassword(email, password).await()
}
withContext(Dispatchers.Main){
Toast.makeText(this@telaLogin, "Login Realizado com Sucesso", Toast.LENGTH_SHORT).show()
val intent = Intent(this@telaLogin, TelaUsuario::class.java)
startActivity(intent)
finish()
}
}catch (e:Exception) {
withContext(Dispatchers.Main){
Toast.makeText(this@telaLogin, e.message, Toast.LENGTH_SHORT).show()
}
}
}
}
}
private fun checkIfUserLoggedIn(){
if(auth.currentUser != null){
val intent = Intent(this@telaLogin, TelaUsuario::class.java)
startActivity(intent)
finish()
}
}
override fun onStart() {
super.onStart()
checkIfUserLoggedIn()
}
private fun selectImage(){
ImagePicker.with(this)
.crop()
.compress(1024)
.maxResultSize(1080, 1080)
.start()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when(resultCode){
Activity.RESULT_OK -> {
fileUri = data?.data
iv_profileImage.setImageURI(fileUri)
}
ImagePicker.RESULT_ERROR -> {
Toast.makeText(this, ImagePicker.getError(data),Toast.LENGTH_SHORT).show()
}
else -> {
Toast.makeText(this, "Tarefa Cancelada!", Toast.LENGTH_SHORT).show()
}
}
}
}
the error that is appearing:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.personalfitness, PID: 8439
java.lang.VerifyError: Verifier rejected class com.example.personalfitness.telaLogin$creatOrLoginUser$1: java.lang.Object com.example.personalfitness.telaLogin$creatOrLoginUser$1.invokeSuspend(java.lang.Object) failed to verify: java.lang.Object com.example.personalfitness.telaLogin$creatOrLoginUser$1.invokeSuspend(java.lang.Object): [0x107] register v3 has type Reference: java.lang.Exception but expected Precise Reference: kotlin.jvm.internal.Ref$ObjectRef (declaration of 'com.example.personalfitness.telaLogin$creatOrLoginUser$1' appears in /data/app/com.example.personalfitness-GTyuUkIpC72oD49ruXnAGQ==/base.apk!classes2.dex)
at com.example.personalfitness.telaLogin.creatOrLoginUser(telaLogin.kt:58)
at com.example.personalfitness.telaLogin.access$creatOrLoginUser(telaLogin.kt:23)
at com.example.personalfitness.telaLogin$buttonClicks$1.onClick(telaLogin.kt:41)
at android.view.View.performClick(View.java:6600)
at android.view.View.performClickInternal(View.java:6577)
at android.view.View.access$3100(View.java:781)
at android.view.View$PerformClick.run(View.java:25912)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
I/Process: Sending signal. PID: 8439 SIG: 9
Disconnected from the target VM, address: 'localhost:8603', transport: 'socket'
I don’t know what else to do