Java.Lang.NullPointerException:尝试调用虚拟方法'void com.google.firebase.auth.FirebaseAuth.zza

问题描述 投票:0回答:1

我正在通过遵循Xamarin Android上的Google official documentation,尝试使用电话号码在Android上实现Firebase身份验证。但我收到此错误:

Java.Lang.NullPointerException: 'Attempt to invoke virtual method 'void com.google.firebase.auth.FirebaseAuth.zza(java.lang.String, long, java.util.concurrent.TimeUnit, com.google.firebase.auth.PhoneAuthProvider$OnVerificationStateChangedCallbacks, android.app.Activity, java.util.concurrent.Executor, boolean)' on a null object reference'

我创建了一个Android Studio项目,并且发送短信没有错误。我原本应该昨天发布应用程序,但是我被困在这里。

注意:我已经引用了Xamarin.GooglePlayServices.BaseXamarin.Firebase.Auth:71.1605.0,并且我有一个带有推送通知FCM的代码,它工作正常。

这是我的MainActivity.OnCreate代码:

        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(savedInstanceState);

        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
        LoadApplication(new App());

        Xamarin.FormsMaps.Init(this, savedInstanceState);

        FirebaseApp firebaseApp = FirebaseApp.InitializeApp(this);

        var firebaseAuthInstance = FirebaseAuth.GetInstance(firebaseApp);

        if(firebaseAuthInstance == null)
        {
            firebaseAuthInstance = new FirebaseAuth(firebaseApp);
        }

        verificationStateChangedCallbacks = new VerificationStateChangedCallbacks(); //This class is below.

        PhoneAuthProvider.Instance.VerifyPhoneNumber("+16505559999", 60, TimeUnit.Seconds, this //The activity, verificationStateChangedCallbacks); // I got the error here

Class VerificationStateChangedCallbacks

public class VerificationStateChangedCallbacks : OnVerificationStateChangedCallbacks
    {
        public override void OnVerificationCompleted(PhoneAuthCredential p0)
        {
        }

        public override void OnVerificationFailed(FirebaseException p0)
        {
        }

        public override void OnCodeSent(string p0, ForceResendingToken p1)
        {
            base.OnCodeSent(p0, p1);
        }
    }
firebase xamarin.forms xamarin.android
1个回答
0
投票

您是否可以检查“ PhoneAuthProvider.Instance”是否为空对象。如果是,请检查您的文件“ google-services.json”。通常,“ FirebaseAuth.GetInstance(firebaseApp)”不会返回null。

© www.soinside.com 2019 - 2024. All rights reserved.