Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] Paho Java: NullPointerException when reconnecting

Hi All,

I have a basic question about how to use the reconnect method on MqttClient and MqttClient. Is the reconnect method on MqttClient and MqttClient only for Paho's atumatic connect?

It is not mentioned in the documents, so this was a little bit confusing.

When I call this method in the connectionLost callback (MqttCallback), it seems that NullPointerException happens in the MqttAsyncClient::stopReconnectCycle.

--- connectionLost callback in my cose
public void connectionLost(Throwable cause) {
    try {
        sampleClient.reconnect(); // null pointer exception
    } catch (MqttException e) {

NullPointerException is thrown when MqttAsyncClient tries to cancel the reconnectTimer because this is initialized only if atumatic connect is true. The exception is caught in CommsCallback's connectionLost, so the execption does not propagate.

private void stopReconnectCycle(){
    String methodName = "stopReconnectCycle";
    //@Trace 504=Stop reconnect timer for client: {0}
    log.fine(CLASS_NAME, methodName, "504", new Object[]{this.clientId});
    reconnectDelay = 1000; // Reset Delay Timer


Yohei Onishi
OGIS-RI Co.,Ltd.
Tel: 050-3367-1634

Back to the top