Android Question java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference

Åke Johansson Bravida

Member
Licensed User
Longtime User
Hi.

I use jMQTT with code i was using in previous version on B4A. Now i have to change login credentials to another MQTT broker.

I use B4A 13.10 (64 bit) I receive error on this line
client.initialize:
client.Initialize("client", "freemqttbroker.sfodo.crystalmq.com:1883", clientId)
I get this error message
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at org.eclipse.paho.client.mqttv3.MqttConnectOptions.validateURI(MqttConnectOptions.java:457)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:273)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:167)
at anywheresoftware.b4j.objects.MqttAsyncClientWrapper.Initialize(MqttAsyncClientWrapper.java:51)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.TempSensor.starter._connectandreconnect(starter.java:303)
at b4a.TempSensor.starter._reconnect_tick(starter.java:568)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7649)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

When I used this code I didn't receive this error.
client.initialize1:
client.Initialize("client", "ssl://m24.cloudmqtt.com:24471", clientId)
I don't use ssl anymore.

Something needed to update?
 

drgottjr

Expert
Licensed User
Longtime User
you have to prepend "tcp://". but that just opens the door to another problem. i thought there might be an issue with the library, but i had no problem messaging using it with mosquitto. looks like there's something funny with crystalmq. see below. crystalmq works fine
 
Last edited:
Upvote 0

Åke Johansson Bravida

Member
Licensed User
Longtime User
you have to prepend "tcp://". but that just opens the door to another problem. i thought there might be an issue with the library, but i had no problem messaging using it with mosquitto. looks like there's something funny with crystalmq.

Ok, yes thank you now I got no error in code but I can't log in. I use same credentials to log in from arduino MKR1010 there are no problems.
cloudmqtt.com have shut down and I need to find another free mqtt broker. Do you know if thera are free broker that I can use?
TCP:// code:
client.Initialize("tommyjohansson", "tcp://freemqttbroker.sfodo.crystalmq.com:1883", clientId)
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i do not use crystalmq, but i set up an account to see what's what. i have no difficulty sending/receiving messages. there is a lot of initial setup at their website. i would suggest you return to the website and make sure everything is in order. while the mqtt protocol may be the same across clients and brokers, each broker may implement things a little differently. i repeat: i had never used crystalmq until toay, but i set up an account and in 5 minutes i was able to send and receive messages. my guess is you are doing something wrong, but i have no way of knowing what. the library worked just fine using tcp:// and port 1883.
 
Last edited:
Upvote 0
Top