sacOO7 / socketcluster-client-java

Native java and android client for socketcluster framework in node.js
http://socketcluster.io/
Apache License 2.0
94 stars 42 forks source link

AndroidRuntime: FATAL EXCEPTION #19

Open nitinagr opened 6 years ago

nitinagr commented 6 years ago

My connection with SC getting disconnected sometimes and when i try to send some msg app crashes with below error can you please help me here.

shutting down VM 11–13 09:20:56.221 3371–3371/git.cluster.io.socketclusterandroid E/AndroidRuntime: FATAL EXCEPTION: main Process: git.cluster.io.socketclusterandroid, PID: 3371 java.lang.NullPointerException: Attempt to invoke virtual method ‘void io.github.sac.Socket$Channel.publish(java.lang.Object)’ on a null object reference at git.cluster.io.socketclusterandroid.MainActivity$5.onClick(MainActivity.java:146) at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:157) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.Act

sacOO7 commented 6 years ago

Hey please make sure you are creating channel first and then publish on it.

Socket.Channel channel = socket.createChannel(channelName);

       // message can have any data type
    /**
     * without acknowledgement
     */
     channel.publish(message);

    /**
     * with acknowledgement
     */
       channel.publish(message, new Ack() {
                public void call(String channelName,Object error, Object data) {
                    if (error == null) {
                        System.out.println("Published message to channel "+channelName+" successfully");
                    }
                }
        });
nitinagr commented 6 years ago

That i am doing but when the connection is broken this exception crash the app.There should be a way to catch this exception and handle gracefully.

sacOO7 commented 6 years ago

I think that shouldn't create a problem. I'm sure of that. Can you check if channel object become null after connection is broken.

sacOO7 commented 6 years ago

Hi @nitinagr is your problem got solved? If it is let me know, I am closing this issue soon

nitinagr commented 6 years ago

Yes resolved.Please close it.

On Thu, Jan 25, 2018 at 12:37 AM, sachin shinde notifications@github.com wrote:

Hi @nitinagr https://github.com/nitinagr is your problem got solved? If it is let me know, I am closing this issue soon

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sacOO7/socketcluster-client-java/issues/19#issuecomment-360240062, or mute the thread https://github.com/notifications/unsubscribe-auth/ACzXABgzpgs8Q82qW--lUpkBXyHi-4eCks5tN39ogaJpZM4QcE4U .