I'm using `trySend()` inside of a `callbackFlow {}...
# coroutines
l
I'm using
trySend()
inside of a
callbackFlow {}
Builder. I'm getting the following exception:
Copy code
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object kotlinx.coroutines.channels.ChannelResult.unbox-impl()' on a null object reference
The code is a location updates listener on Android
Copy code
callbackFlow {

        timeoutTimer?.cancelTimer()
        timeoutTimer = LifecycleAwareTimer { onTimeout?.invoke() }
        timeoutTimer?.startTimer(timeoutInSeconds * 1000L)

        locationCallback = object : LocationCallback() {
            override fun onLocationResult(location: LocationResult) {
                location.lastLocation?.let {
                    if (it.accuracy <= minAcceptableAccuracyMeters) {
                        timeoutTimer?.cancelTimer()
                        trySend(LocationState.Success(it))
                    }
                }
            }
        }.apply {
            if ((permissionChecker.locationPermissionsGranted && permissionChecker.hasGPS && permissionChecker.isGPSTurnedOn)) {
                fusedLocationProvider.requestLocationUpdates(locationRequest, this, Looper.getMainLooper())
                    .addOnFailureListener { e ->
                        trySend(LocationState.Failure.Generic)
                        close(e)
                    }
            } else {
                trySend(LocationState.Failure.LocationPermissionsNotGranted)
            }
        }

        awaitClose { stopEmittingLocationUpdates() }

    }
The exception is in the first
trySend(LocationState.Success(it))