0

您好,我正在使用AndroidAsync。如果我尝试向 WebSocket 发送消息并且连接断开,我会收到 FATAL EXCEPTION

    03-20 11:54:53.064: E/AndroidRuntime(13805): FATAL EXCEPTION: AsyncServer
    03-20 11:54:53.064: E/AndroidRuntime(13805): Process: com.example.playerappv2, PID: 13805
    03-20 11:54:53.064: E/AndroidRuntime(13805): java.lang.RuntimeException: java.lang.NullPointerException
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:613)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.AsyncServer.access$4(AsyncServer.java:596)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:552)
    03-20 11:54:53.064: E/AndroidRuntime(13805): Caused by: java.lang.NullPointerException
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.example.playerappv2.core.WebSocketServices$1.onCompleted(WebSocketServices.java:128)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.http.AsyncHttpClient$8.onConnectCompleted(AsyncHttpClient.java:581)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.http.AsyncHttpClient.reportConnectedCompleted(AsyncHttpClient.java:122)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.http.AsyncHttpClient.access$1(AsyncHttpClient.java:110)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.http.AsyncHttpClient$3.onConnectCompleted(AsyncHttpClient.java:225)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.AsyncServer$7.onCompleted(AsyncServer.java:377)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.AsyncServer$7.onCompleted(AsyncServer.java:1)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java:96)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:130)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:113)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.future.TransformFuture.error(TransformFuture.java:22)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.future.TransformFuture.onCompleted(TransformFuture.java:9)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java:96)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:130)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.AsyncServer$8$2.run(AsyncServer.java:412)
    03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.AsyncServer.lockAndRunQueue(AsyncServer.java:686)
    03-20 11:54:53.064: E/Andr

oidRuntime(13805):  at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:697)
03-20 11:54:53.064: E/AndroidRuntime(13805):    at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:607)
03-20 11:54:53.064: E/AndroidRuntime(13805):    ... 2 more

有谁知道如何抓住这个,并且不允许应用程序崩溃?这是日志引用崩溃行的相同代码......

private void connectToPASocket(String SOCKET_ADDR) {
    Log.i(TAG, "connectToPASocket()");

    // Checking
    if (socket != null && socket.isOpen()) return;


    // Initiate web socket connection
    AsyncHttpClient.getDefaultInstance().websocket(SOCKET_ADDR, null, new AsyncHttpClient.WebSocketConnectCallback() {
                @Override
                public void onCompleted(Exception ex, WebSocket webSocket) {
                    Log.i(TAG, "onCompleted");
                    socket = webSocket;


                    if (ex != null) {
                        Log.e(TAG, "onCompleted > if (ex != null)");
                        ex.printStackTrace();
                        return;
                    }
                    //HERE CRASH refered too
4

0 回答 0