B4J Question MQTT connection problem in B4J

ciapw

Member
Licensed User
Hi all! I am trying to implement Mqtt connection with a button. So when button is pressed, the LED will turn on and publish message to cynthia/status (mytopic). The button and Led are working nicely, but it seems the message could not be published. Please comment if you find something strange in my simple code . Thanks

Error Log :

B4X:
Waiting for debugger to connect...
Program started.
monitoring state
stop
stop2
nyala -> 'the button is pressed then this error come'
Error occurred on line: 61 (Main)
java.lang.NullPointerException
    at anywheresoftware.b4j.objects.MqttAsyncClientWrapper.Publish2(MqttAsyncClientWrapper.java:100)
    at anywheresoftware.b4j.objects.MqttAsyncClientWrapper.Publish(MqttAsyncClientWrapper.java:97)
    at b4j.example.main._tombolnc(main.java:182)
    at b4j.example.main._timer1_tick(main.java:154)
    at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:614)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent
2(ShellBA.java:93)
    at anywheresoftware.b4a.objects.Timer$TickTack$1.run(Timer.java:118)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:114)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:146)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:303)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
    at b4j.example.main.main(main.java:29)
 

ciapw

Member
Licensed User
Okay then. I feel ashamed because this is a stupid mistake so that's why at first I asked you to delete this thread

But if anyone using NanoPi has this kind of similar problem, check this :

It turns out that my NanoPi is not connected to the internet. Then I connect my NanoPi with LAN Cable through a switch hub that connected to a router.
So if you are using MQTT connection please make sure you connected your NanoPi to the hub/router that connected to the internet because NanoPi basically is not connected to internet even you have connected a LAN cable from your NanoPI to your laptop

Many thanks ALL !
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…