paho.mqtt.android
paho.mqtt.android copied to clipboard
java.lang.NullPointerException: Attempt to invoke virtual method 'long org.eclipse.paho.client.mqttv3.internal.ClientState.getKeepAlive()' on a null object reference
No clue about your implementation, but you miss call of override fun init(comms: ClientComms)
I implemented it like this
fun connectMqttClient(
context: Context,
userId: String?,
flexId: String? = ""
): Flow<Pair<Boolean, MqttAndroidClient>> = callbackFlow {
mqttClient = MqttAndroidClient(
context,
BuildConfig.MQTT_DOMAIN,
"android_${userId}_$deviceId${MqttClient.generateClientId()}"
)
mqttClient.setCallback(object : MqttCallback {
override fun messageArrived(topic: String?, message: MqttMessage?) {
Timber.tag(TAG).d("messageArrived ${message.toString()}")
busEvent(MessageMqtt(message = message.toString(), topic = topic))
}
override fun connectionLost(cause: Throwable?) {
mqttClient.reconnect()
Timber.tag(TAG).d("Connection lost ${cause.toString()}")
}
override fun deliveryComplete(token: IMqttDeliveryToken?) {
}
})
val options = MqttConnectOptions()
options.isAutomaticReconnect = true
try {
mqttClient.connect(options, null, object : IMqttActionListener {
override fun onSuccess(asyncActionToken: IMqttToken?) {
trySend(Pair(true, mqttClient))
}
override fun onFailure(asyncActionToken: IMqttToken?, exception: Throwable?) {
trySend(Pair(false, mqttClient))
}
})
} catch (e: MqttException) {
e.printStackTrace()
}
awaitClose { mqttClient.connect() }
}
This extendedSample works properly, and maybe can be improved on several ways. But this is not the issue.
if you have the running code, it should not be very difficult, to debug your code. When you found an issue, please show me how to improve
Or you can make a pull request eg. in basicSample with your implementation and demonstrate what's going wrong. I would love to see here flow in action. But with a code snippet alone, I can't do nothing
Do you have any news? i'm facing the same issue.
Do you have any news? i'm facing the same issue.
But i'm not able to recreate the scenario, only getting this in firebase crashlytics
The label A sample is required
is still valid
Without running sample I close it. You can reopen it if you still need it
No clue about your implementation, but you miss call of override fun init(comms: ClientComms)
Can you please elaborate on "you missed call of init(comms)"? Were should we init it?
I tried reproducing it, but couldnt but we are getting crashlytics data hence trying to understand what might have gone wrong.