Is there Kotlin documentation at all? I'm getting a Bluetooth Exception I need help debugging

I tried to get Acceleration data out of my MetaMotion R and I'm getting a bluetooth exception I don't quite understand.

` fun startGettingAccelerationData() {
try {
accelerometer = metaWearBoard.getModule(AccelerometerBmi160::class.java)
Timber.d("METAWEAR Accelerometer: %s", accelerometer)
accelerometer.configure()
.odr(AccelerometerBmi160.OutputDataRate.ODR_25_HZ) // set odr to 25Hz
.range(AccelerometerBosch.AccRange.AR_4G) // set range to +/-4g
.commit()

        accelerometer.acceleration().addRouteAsync {  }

        accelerometer.acceleration().addRouteAsync(RouteBuilder { source ->
            source.stream(object : Subscriber {
                override fun apply(data: Data?, vararg env: Any?) {
                    data?.let {
                        val acceleration: Acceleration = it.value(Acceleration::class.java)
                        Timber.d("METAWEAR - Data %s", acceleration.toString())
                    }
                }
            })
        }).continueWith(object : Continuation<Route, Void> {
            @Throws(Exception::class)
            override fun then(task: Task<Route>): Void? {
                accelerometer.start()
                return null
            }
        })
    } catch (exception: Exception) {
        Timber.e(exception)
    }
}`

And here's the exception I get when I try to run it this way:

2019-08-13 00:44:50.682 21820-21962/com.onepeloton.studio.dev W/BluetoothGatt: Unhandled exception in callback java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter env at com.testapp.sample.MetawearSensorReceiver$startGettingAccelerationData$1$1.apply(Unknown Source:7) at com.mbientlab.metawear.impl.DeviceDataConsumer.call(DeviceDataConsumer.java:51) at com.mbientlab.metawear.impl.StreamedDataConsumer.lambda$addDataHandler$4(StreamedDataConsumer.java:155) at com.mbientlab.metawear.impl.-$$Lambda$StreamedDataConsumer$b3JFDLkGI0Pi2mtR2I-nobGuhUc.onResponseReceived(Unknown Source:4) at com.mbientlab.metawear.impl.JseMetaWearBoard.lambda$null$17(JseMetaWearBoard.java:796) at com.mbientlab.metawear.impl.-$$Lambda$JseMetaWearBoard$OnC0yYpmZcKMMHqzlWEtJ-kw-x8.onChange(Unknown Source:2) at com.mbientlab.metawear.android.BtleService$1.onCharacteristicChanged(BtleService.java:179) at android.bluetooth.BluetoothGatt$1$8.run(BluetoothGatt.java:519) at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:876) at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:43) at android.bluetooth.BluetoothGatt$1.onNotify(BluetoothGatt.java:513) at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:185) at android.os.Binder.execTransact(Binder.java:739)

Comments

  • edited August 2019

    Stack trace tells you what is wrong.
    kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter env at com.testapp.sample.MetawearSensorReceiver$startGettingAccelerationData$1$1.apply(Unknown Source:7)

  • I'm having the same issue. The Subscriber interface defines the apply method like this:
    void apply(Data data, Object ... env);

    But then seems to proceed to invoke it with null for the second parameter. Question is why this is happening. This parameter apparently is influenced by the route creation. But I haven't seen anything in the documentation that would have an effect...

  • According to this SO answer: https://stackoverflow.com/questions/49051861/passing-null-as-part-of-vararg-parameter-to-java-method-from-kotlin
    it could also be a null return value. No idea though how this would be the case here, as apply does not return anything...

  • @calfilmmaker Have you solved this issue?

  • Ok, seems this was an issue with creation of the subscriber. The way it works for me:

    dataProducer?.addRouteAsync {
        it.stream { data, env ->
            // do stuff with data and env here
        }
    }
    

    I don't really know why it works this way and not if you implement subscriber and do it.stream(MySubscriber()) though...

Sign In or Register to comment.