arcoirislabs / cordova-plugin-mqtt

MqTT Cordova Plugin for Apache Cordova (> v3.0)
MIT License
86 stars 49 forks source link

When subscribe ,error: java.lang.NullPointerException #28

Closed malaimoo closed 7 years ago

malaimoo commented 7 years ago

my code is

 cordova.plugins.CordovaMqTTPlugin.subscribe({
            topic: "vip/shop/" + newValue + "/personInfo",
            qos: 0,
            success: function (s) {
            },
            error: function (e) {
            }
          });

but it comes to an error:

java.lang.NullPointerException: Attempt to invoke virtual method 'org.eclipse.paho.client.mqttv3.IMqttToken org.eclipse.paho.client.mqttv3.MqttAsyncClient.subscribe(java.lang.String, int, java.lang.Object, org.eclipse.paho.client.mqttv3.IMqttActionListener)' on a null object reference
07-15 14:40:00.078  4535  4535 E AndroidRuntime:    at com.arcoirislabs.plugin.mqtt.CordovaMqTTPlugin.subscribe(CordovaMqTTPlugin.java:273)
07-15 14:40:00.078  4535  4535 E AndroidRuntime:    at com.arcoirislabs.plugin.mqtt.CordovaMqTTPlugin.access$200(CordovaMqTTPlugin.java:24)
07-15 14:40:00.078  4535  4535 E AndroidRuntime:    at com.arcoirislabs.plugin.mqtt.CordovaMqTTPlugin$3.run(CordovaMqTTPlugin.java:76)
07-15 14:40:00.078  4535  4535 E AndroidRuntime:    at android.os.Handler.handleCallback(Handler.java:754)
07-15 14:40:00.078  4535  4535 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:95)
07-15 14:40:00.078  4535  4535 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:160)
07-15 14:40:00.078  4535  4535 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:6200)
07-15 14:40:00.078  4535  4535 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
07-15 14:40:00.078  4535  4535 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
07-15 14:40:00.078  4535  4535 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
arcoirislabs commented 7 years ago

Hi, You can use our topic router and subscribe to a wildcard topic from subscribe method. The topic router will give you a chance to write either the switch case based eventlistner or individual event listeners

Sent from my iPhone

On 15-Jul-2017, at 3:21 PM, malaimoo notifications@github.com wrote:

my code is

cordova.plugins.CordovaMqTTPlugin.subscribe({ topic: "vip/shop/" + newValue + "/personInfo", qos: 0, success: function (s) { }, error: function (e) { } }); but it comes to an error:

java.lang.NullPointerException: Attempt to invoke virtual method 'org.eclipse.paho.client.mqttv3.IMqttToken org.eclipse.paho.client.mqttv3.MqttAsyncClient.subscribe(java.lang.String, int, java.lang.Object, org.eclipse.paho.client.mqttv3.IMqttActionListener)' on a null object reference 07-15 14:40:00.078 4535 4535 E AndroidRuntime: at com.arcoirislabs.plugin.mqtt.CordovaMqTTPlugin.subscribe(CordovaMqTTPlugin.java:273) 07-15 14:40:00.078 4535 4535 E AndroidRuntime: at com.arcoirislabs.plugin.mqtt.CordovaMqTTPlugin.access$200(CordovaMqTTPlugin.java:24) 07-15 14:40:00.078 4535 4535 E AndroidRuntime: at com.arcoirislabs.plugin.mqtt.CordovaMqTTPlugin$3.run(CordovaMqTTPlugin.java:76) 07-15 14:40:00.078 4535 4535 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:754) 07-15 14:40:00.078 4535 4535 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95) 07-15 14:40:00.078 4535 4535 E AndroidRuntime: at android.os.Looper.loop(Looper.java:160) 07-15 14:40:00.078 4535 4535 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6200) 07-15 14:40:00.078 4535 4535 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 07-15 14:40:00.078 4535 4535 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874) 07-15 14:40:00.078 4535 4535 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764) — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.