Android Question MQTT subscribe issue (maybe..)

giggetto71

Active Member
Licensed User
Longtime User
Hi guys,
I have a published app on the google market which sometimes logs a java.lang.NullPointerException on subscribe.
this is what I get in the Android vitals

java.lang.NullPointerException:
at anywheresoftware.b4j.objects.MqttAsyncClientWrapper.Subscribe (MqttAsyncClientWrapper.java:116)
at gigiosoft.MQTTAlert.mqttservice._mqtt_connected (mqttservice.java:630)
at java.lang.reflect.Method.invoke (Native Method)
at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:196)
at anywheresoftware.b4a.BA$2.run (BA.java:370)
at android.os.Handler.handleCallback (Handler.java:883)
at android.os.Handler.dispatchMessage (Handler.java:100)
at android.os.Looper.loop (Looper.java:241)
at android.app.ActivityThread.main (ActivityThread.java:7604)
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:941)

I am skretching my head to get my hands around the issue but I don't know how to troubleshoot this as it does not crash on my phones.
From what I can read from the logs the app crashes on subscribe, so I was thinking that maybe the client is not connected when the subscribe method is called but I actually do that in the mqtt_connected event so I don't understand how that may be possible.
this is the conceptual code I use:

B4X:
Sub mqtt_Connected (Success As Boolean)
  
    If Success = False Then
        Log(LastException)   
        'code for connection failed
    Else
       ' some code for connection succes
       '..............................
       'subsctibe to all alerts topic.
       For ii = 0 To AlertsList.Size-1
          AlertElem = AlertsList.GetValueAt(ii) ' get my object from a list
          mqtt.Subscribe(AlertElem.Topic,AlertElem.Qos)   ' call subscribe              
       Next
               
    End If
    
End Sub


Any idea?
thanks!!!
 
Top