deepstream.io-client-java icon indicating copy to clipboard operation
deepstream.io-client-java copied to clipboard

Unsubscribe throw NPE

Open yan5 opened this issue 8 years ago • 4 comments

I'm running into the following error

Caused by: java.lang.NullPointerException: 
Attempt to invoke interface method 'void io.deepstream.Endpoint.send(java.lang.String)' on a null object reference
                                                                   at io.deepstream.Connection.send(Connection.java:114)
                                                                   at io.deepstream.EventHandler.unsubscribe(EventHandler.java:68)

when I'm trying to unsubscribe in onDestroy() as
deepstreamClient.event.unsubscribe(channel, mChatEventListener);

the deepstreamClient was initialized as deepstreamClient = new DeepstreamClient(url);

Any idea?

yan5 avatar Jan 14 '17 14:01 yan5

It appears the connection was lost and hence your trying to send something on a closed state.

What hook is 'onDestroy' exactly?

yasserf avatar Jan 14 '17 15:01 yasserf

onDestroy() on Activity.

I was trying to close/unsubscribe to avoid any memory leak, coz these EvenListeners are anonymous inner classes. Is there any other cleaner way to remove them?

I guess it would great if we could add api's for

  • removing those listeners (all listener or by channel name)
  • removing ConnectionChangeListeners and RuntimeErrorHandlers

which can be used while closing or destroying the activity to avoid memory leaks.

yan5 avatar Jan 18 '17 00:01 yan5

Are you creating a new connection per activity?

yasserf avatar Jan 18 '17 08:01 yasserf

Yes. Coz activities are independent in nature in my case. Do you suggest any alternatives? in either case it would be great if we could get clean api to tear down and clean up.

yan5 avatar Jan 18 '17 12:01 yan5