gpt4 book ai didi

android - FirebaseFirestore.getInstance() 给出空指针异常

转载 作者:行者123 更新时间:2023-11-29 02:24:01 25 4
gpt4 key购买 nike

我在我的应用中运行 Firebase Firestore。我在调用前两行时得到空指针异常:

FirebaseApp.initializeApp(this)
val db = FirebaseFirestore.getInstance()

来自 build.gradle - 项目:

classpath 'com.google.gms:google-services:4.1.0' (also tried 4.0.0)

来自 build.gradle - 应用程序:(目前最新)

implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-firestore:17.1.3'

如果我在创建实例时设置断点 - 我最终会在 ActivityThread 类 - registerOnActivityPausedListener 方法。 http://take.ms/Fdh7z

代码绝对没问题,因为它可以在其他设备上运行。但是在其中一个(Wileyfox Swift 2)上我得到了 NLP 并且没有很好的解释:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.firebase.auth.internal.zzab.zzf(int)' on a null object reference
at com.google.firebase.auth.FirebaseAuth.addIdTokenListener(Unknown Source)
at com.google.firebase.firestore.auth.FirebaseAuthCredentialsProvider.<init>(com.google.firebase:firebase-firestore@@17.1.3:76)
at com.google.firebase.firestore.FirebaseFirestore.newInstance(com.google.firebase:firebase-firestore@@17.1.3:109)
at com.google.firebase.firestore.FirestoreMultiDbComponent.get(com.google.firebase:firebase-firestore@@17.1.3:51)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@17.1.3:87)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@17.1.3:72)
at com.myjob.exchange.activity.SplashActivity.onCreate(SplashActivity.kt:25)
at android.app.Activity.performCreate(Activity.java:6723)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)

最佳答案

确保您已将您的应用程序与 Firebase (google-services.json) 文件相关联,然后试试这个:

FirebaseFirestore db = FirebaseFirestore.getInstance();
FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
.setTimestampsInSnapshotsEnabled(true)
.build();
db.setFirestoreSettings(settings);

关于android - FirebaseFirestore.getInstance() 给出空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53339539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com