应用程序在使用 deepstream 更改连接时崩溃

App crashes on connection change using deepstream

当我更改连接时,我的应用程序崩溃并显示以下堆栈跟踪:

E/AndroidRuntime: FATAL EXCEPTION: Timer-3
    Process: com.app.teemchat, PID: 9383
    io.deepstream.DeepstreamException: CONNECTION_ERROR: null
        at io.deepstream.DeepstreamClientAbstract.onError(DeepstreamClientAbstract.java:59)
        at io.deepstream.Connection.run(Connection.java:187)
        at java.util.TimerThread.mainLoop(Timer.java:555)
        at java.util.TimerThread.run(Timer.java:505)

请帮我解决这个问题...

client.addConnectionChangeListener(new ConnectionStateListener() {
    @Override
    public void connectionStateChanged(ConnectionState connectionState) throws RuntimeException {
        Log.w(Tag, "ConnectionChange>>> " + connectionState.toString());
        if (connectionState.toString().equalsIgnoreCase(ConnectionState.ERROR.toString())) {
           client.close();
           doLogin();
           }

           if (connectionState.toString().equalsIgnoreCase(ConnectionState.CLOSED.toString())) {
              doLogin();
              }
        }
});

AlexBHarley 说您需要添加 setRuntimeErrorHandler https://github.com/deepstreamIO/deepstream.io-client-java/issues/85

this is expected in the sense that the connection has died, so there is a CONNECTION_ERROR. If you don't want this to throw an exception you can put a listener on the error event with client.setRuntimeErrorHandler. Admittedly the reason could be better than null. The current approach is either one of two things,

infinite reconnect attempts store some local state and restart the session when internet connectivity comes back. We're hoping to tackle some better offline first functionality with resuming sessions and the like, in the near future.