Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
google auth显示java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“int android.view.view.getVisibility()”_Android_Kotlin_Firebase Authentication_Google Authentication - Fatal编程技术网

google auth显示java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“int android.view.view.getVisibility()”

google auth显示java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“int android.view.view.getVisibility()”,android,kotlin,firebase-authentication,google-authentication,Android,Kotlin,Firebase Authentication,Google Authentication,我计划使用Firebase Auth和Google制作一个应用程序。但是当我从google按钮中选择我的google帐户时,它会在本文末尾显示以下错误消息。另外,请注意startActivityForResult已弃用。我真的很感激在这方面的帮助,因为我是科特林的新手 多谢各位 Xml代码 错误 这是一个关于SHA1指纹的问题…在我删除了在谷歌云平台上创建的Oauth客户端后得到解决…然后在Firebase中使用相同的SHA1指纹进行更新 ……就这样成功了 这回答了你的问题吗? <

我计划使用Firebase Auth和Google制作一个应用程序。但是当我从google按钮中选择我的google帐户时,它会在本文末尾显示以下错误消息。另外,请注意startActivityForResult已弃用。我真的很感激在这方面的帮助,因为我是科特林的新手

多谢各位

Xml代码

错误


这是一个关于SHA1指纹的问题…在我删除了在谷歌云平台上创建的Oauth客户端后得到解决…然后在Firebase中使用相同的SHA1指纹进行更新
……就这样成功了

这回答了你的问题吗?
    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".adapters.Sign_in_page">


    <com.google.android.gms.common.SignInButton
        android:id="@+id/sign_in_button"
        android:layout_width="match_parent"
        android:layout_height="60sp"
        android:layout_marginLeft="50sp"
        android:layout_marginTop="512dp"
        android:layout_marginRight="50sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.16"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
class Sign_in_page : AppCompatActivity() {

    private lateinit var mauth : FirebaseAuth
    private lateinit var mGoogleSignInClient: GoogleSignInClient
    private val RC_SIGN_IN = 9001

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_sign_in_page)

        val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken("972503126282-sv3aqkustdhtq49a605hnvauubroht95.apps.googleusercontent.com")
            .requestEmail()
            .build()

        mGoogleSignInClient = GoogleSignIn.getClient(this, gso)

        mauth = FirebaseAuth.getInstance()
  sign_in_button.setOnClickListener {
            resultLauncher.launch(Intent(mGoogleSignInClient.signInIntent))
        }  var resultLauncher = registerForActivityResult(StartActivityForResult()) { result ->
        if (result.resultCode == Activity.RESULT_OK) {
            val intent: Intent? = result.data
            val task = GoogleSignIn.getSignedInAccountFromIntent(intent)
            try {

                val account = task.getResult(ApiException::class.java)!!
                firebaseAuthWithGoogle(account.idToken!!)

            } catch (e: ApiException) {
                Toast.makeText(this, "Sign In Failed!", Toast.LENGTH_SHORT).show()

            }
        }
    }
  override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
        if (requestCode == RC_SIGN_IN) {
            val task = GoogleSignIn.getSignedInAccountFromIntent(data)
            try {
                // Google Sign In was successful, authenticate with Firebase
                val account = task.getResult(ApiException::class.java)!!
                //Log.d("TAG", "firebaseAuthWithGoogle:" + account.id)
                firebaseAuthWithGoogle(account.idToken!!)
            } catch (e: ApiException) {
                // Google Sign In failed, update UI appropriately
               // Log.w("TAG", "Google sign in failed", e)
                // ...
            }
        }
    }



    private fun firebaseAuthWithGoogle(idToken: String) {
        val credential = GoogleAuthProvider.getCredential(idToken, null)
        mauth.signInWithCredential(credential)
                .addOnCompleteListener(this) { task ->
                    if (task.isSuccessful) {
                        // Sign in success, update UI with the signed-in user's information
                      //  Log.d("TAG", "signInWithCredential:success")
                        val user = mauth.currentUser
                      //  updateUI(user)
                    } else {
                        // If sign in fails, display a message to the user.
                       // Log.w("TAG", "signInWithCredential:failure", task.exception)
                        // ...
                        Toast.makeText(this, "Authentication Failed.", Toast.LENGTH_SHORT).show()
                       // updateUI(null)
                    }

                    // ...
                }
    }
}
W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getVisibility()' on a null object reference
W/System.err:     at android.view.ViewRootImpl.getHostVisibility(ViewRootImpl.java:1806)
        at android.view.ViewRootImpl.handleAppVisibility(ViewRootImpl.java:1442)
        at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:4838)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7078)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)