'Firebase coroutines onSuccessListener error
I've been getting this:
java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter it
at com.bumtzihaus.app.data.AdminRepository.addLogItem_gIAlu_s$lambda-4(Unknown Source:7)
at com.bumtzihaus.app.data.AdminRepository.$r8$lambda$34A54R8CS3e1Wdzy3o1dgUPicmE(Unknown Source:0)
at com.bumtzihaus.app.data.AdminRepository$$ExternalSyntheticLambda8.onSuccess(Unknown Source:4)
at com.google.android.gms.tasks.zzm.run(com.google.android.gms:play-services-tasks@@18.0.0:1)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
for certain firestore queries; it's worked fine and all of a sudden I keep getting this error. Here's what I'm trying to call:
ref.set(
hashMapOf(
"logCode" to bumtziLog.logCode,
"timestamp" to FieldValue.serverTimestamp(),
"itemText" to bumtziLog.items,
"users" to bumtziLog.users,
"sessions" to bumtziLog.sessions
)
).addOnSuccessListener {
result = Result.success(Unit)
}.addOnFailureListener { exception ->
result = Result.failure(exception)
exception.printStackTrace()
Firebase.crashlytics.recordException(exception)
}.await()
It seems to be complaining about a null lambda for onSuccessListener
Solution 1:[1]
This was an error on Google's part - update to the latest Firebase version and you should get rid of this error.
Solution 2:[2]
I'm not sure if it helps, but try to add explicit nullable parameter of type Any? for addOnSuccessListener lambda:
ref.set(
hashMapOf(
"logCode" to bumtziLog.logCode,
"timestamp" to FieldValue.serverTimestamp(),
"itemText" to bumtziLog.items,
"users" to bumtziLog.users,
"sessions" to bumtziLog.sessions
)
).addOnSuccessListener { someResult: Any? ->
result = Result.success(Unit)
}.addOnFailureListener { exception ->
result = Result.failure(exception)
exception.printStackTrace()
Firebase.crashlytics.recordException(exception)
}.await()
Solution 3:[3]
@Sergey answer works but if you don't want to add the parameter on each on success. Just upgrade you firestore gradle dependencies to the latest. In my situation I upgraded com.google.firebase:firebase-bom:29.0.2 to com.google.firebase:firebase-bom:29.0.3 and everything worked out.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vidican Vlad-Radu |
| Solution 2 | BigSt |
| Solution 3 | Paul Kunda |
