在这件事上我是新手,我已经使用了一个指南作为指导,我复制了该指南中所有正确的内容,但是当我想运行该应用程序时,因为出现以下警告而无法这样做:
Unresolved reference: isSuccesful
Unresolved reference: result
Unresolved reference: isSuccesful
Unresolved reference: result
Unresolved reference: FirebaseAuth
这是我的代码:
package com.mpdw55.medic_app
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.FirebaseUser
import kotlinx.android.synthetic.main.activity_auth.*
class AuthActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_auth)
// Analytics Event
val analytics:FirebaseAnalytics = FirebaseAnalytics.getInstance(this)
val bundle = Bundle()
bundle.putString("message", "Integracón de Firebase completa")
analytics.logEvent("Initscreen", bundle)
//setup
setup()
}
private fun setup(){
title = "Autenticación"
signUpButton.setOnClickListener {
if (emailEditTest.text.isNotEmpty() && passwordEditText.text.isNotEmpty()) {
FirebaseAuth.getInstance()
.createUserWithEmailAndPassword(emailEditTest.text.toString(),
passwordEditText.text.toString()).addOnCompleteListener {}
if (it.isSuccesful) {
showHome(it.result?.user?.email?:"", ProviderType.BASIC)
} else {
showAlert()
}
}
}
logInButton.setOnClickListener {
if (emailEditTest.text.isNotEmpty() && passwordEditText.text.isNotEmpty()) {
FirebaseAuth.getInstance()
.signInWithEmailAndPassword(emailEditTest.text.toString(),
passwordEditText.text.toString()).addOnCompleteListener {}
if (it.isSuccesful) {
showHome(it.result?.user?.email?:"", ProviderType.BASIC)
} else {
showAlert()
}
}
}
}
private fun showAlert() {
val builder = AlertDialog.Builder(this)
builder.setTitle("Error")
builder.setMessage("Se ha producido un error autenticando al ususario")
builder.setPositiveButton("Aceptar", null)
val dialog: AlertDialog = builder.create()
dialog.show()
}
private fun showHome(email: String, provider: ProviderType){
val homeIntent = Intent(this, HomeActivity::class.java).apply {
putExtra("email", email)
putExtra("provider", provider.name)
}
startActivity(homeIntent)
}
我的build.gradle(:app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 30
buildToolsVersion "30.0.1"
defaultConfig {
applicationId "com.mpdw55.medic_app"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-core:17.4.4'
implementation 'com.google.firebase:firebase-analytics:17.4.4'
implementation 'com.google.firebase:firebase-auth:19.3.2'
implementation 'com.google.android.gms:play-services-auth:18.1.0'
implementation 'com.firebaseui:firebase-ui-auth:6.3.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
apply plugin: 'com.google.gms.google-services'
有人可以帮我吗?
答案 0 :(得分:0)
您应该尝试将if(it.isSuccesfull){} else {}放在.addOnCompleteListener的括号之间,结果应该是
FirebaseAuth.getInstance()
.createUserWithEmailAndPassword(emailEditTest.text.toString(),
passwordEditText.text.toString()).addOnCompleteListener {
if (it.isSuccesful) {
showHome(it.result?.user?.email?:"", ProviderType.BASIC)
} else {
showAlert()
} }
该错误应该得到解决。您还应该对唱歌进行相同的操作。
logInButton.setOnClickListener {
if (emailEditTest.text.isNotEmpty() && passwordEditText.text.isNotEmpty()) {
FirebaseAuth.getInstance()
.signInWithEmailAndPassword(emailEditTest.text.toString(),
passwordEditText.text.toString()).addOnCompleteListener {
if (it.isSuccesful) {
showHome(it.result?.user?.email?:"", ProviderType.BASIC)
} else {
showAlert()
}}