Home > Net >  Firebase coroutines onSuccessListener error
Firebase coroutines onSuccessListener error

Time:12-18

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

CodePudding user response:

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()
  • Related