简体   繁体   English

Android Studio 调试错误

[英]Android Studio Debug Error

I have a function to run a WebSocket:我有一个运行 WebSocket 的函数:

private void connectWebSocket() {
    URI uri;
    try {
        uri = new URI(WEBSOCKET_URL.concat(token.getString("token")));
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }

    mWebSocketClient = new WebSocketClient(uri) {
        @Override
        public void onOpen(ServerHandshake serverHandshake) {
            Log.i("Websocket", "Opened");
        }

        @Override
        public void onMessage(String s) {
            final String message = s;
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    try {
                        // TODO test it
                        JSONObject json_object = new JSONObject(message);
                        if (json_object.has("chat_message")) {
                            ChatFragment activeChat = null;
                            try {
                                activeChat = getChatFragment();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            JSONObject json_message = json_object.getJSONObject("chat_message");
                            if (activeChat != null && activeChat.getUserTo().getId() == json_message.getInt("user_from")) {
                                    activeChat.addMessage(json_message);
                            } else {
                                User user = getUserById(json_message.getInt("user_from"));
                                sendNotification(json_message, user == null ? json_message.getString("user_from") : user.toString());
                            }

                        } else if (json_object.has("notification")) {
                            JSONObject json_message = json_object.getJSONObject("notification");
                            sendNotification(json_message);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
        }

        @Override
        public void onClose(int i, String s, boolean b) {
            Log.i("Websocket", "Closed " + s);
        }

        @Override
        public void onError(Exception e) {
            Log.i("Websocket", "Error " + e.getMessage());
        }
    };
    mWebSocketClient.connect();
}

If I run the app on Android Studio it works properly.如果我在 Android Studio 上运行该应用程序,它可以正常工作。

But when I debug the app throws error但是当我调试应用程序时会抛出错误

10-25 16:25:21.808 12040-12047/com.cathedralsw.school A/art: art/runtime/jdwp/jdwp_event.cc:661] Check failed: Thread::Current() != GetDebugThread() (Thread::Current()=0x7f84616400, GetDebugThread()=0x7f84616400) Expected event thread 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:422] Runtime aborting... 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:422] Aborting thread: 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:422] "JDWP" prio=5 tid=4 WaitingForDebuggerSend 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:422] | 10-25 16:25:21.808 12040-12047/com.cathedralsw.school A/art: art/runtime/jdwp/jdwp_event.cc:661] 检查失败:Thread::Current() != GetDebugThread() (Thread: :Current()=0x7f84616400, GetDebugThread()=0x7f84616400) 预期事件线程 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc: Runtime .. 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:422] 中止线程:10-25 16:25:21.909 12040/com.1204 cathedralsw.school A/art: art/runtime/runtime.cc:422] "JDWP" prio=5 tid=4 WaitingForDebuggerSend 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/运行时/runtime.cc:422] | group="" sCount=0 dsCount=0 obj=0x12c3c940 self=0x7f84616400 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:422] | group="" sCount=0 dsCount=0 obj=0x12c3c940 self=0x7f84616400 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:4222 sysTid=12047 nice=0 cgrp=default sched=0/0 handle=0x7f8be0b450 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:422] | sysTid=12047 nice=0 cgrp=default sched=0/0 handle=0x7f8be0b450 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:422] state=R schedstat=( 145449425 3440734 128 ) utm=12 stm=2 core=4 HZ=100 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:422] | state=R schedstat=( 145449425 3440734 128 ) utm=12 stm=2 core=4 HZ=100 10-25 16:25:21.909 12040-12047/com.cathedralsw.run.cc/arttime :422] | stack=0x7f8bd11000-0x7f8bd13000 stackSize=1005KB 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:422] | stack=0x7f8bd11000-0x7f8bd13000 stackSize=1005KB 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:422] | held mutexes= "abort lock" 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:422] native: #00 pc 000000000047a0a8 /system/lib64/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+220) 10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:422] native: #01 pc 000000000047a0a4 /system/lib64/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+216) ... ..持有互斥体=“中止锁定”10-25 16:25:21.909 12040-12047/com.cathedralsw.school A/art: art/runtime/runtime.cc:422] native: #00 pc 000000000047a0a4/libart的.so(_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv + 220)10-25 16:25:21.909 12040-12047 / com.cathedralsw.school A /艺术:艺术/运行/ runtime.cc:422]天然:#01 PC 000000000047a0a4 /系统/ lib64下/ libart .so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+216) ... ..

EDIT:编辑:

The problem is debugging and with the WebSocket in runOnUiThread(new Runnable() {...问题是调试和 runOnUiThread(new Runnable() {...

Solved!解决了!

Disable Instant Run in Android Studio Settings -> Build, Execution, Deployment在 Android Studio 设置中禁用 Instant Run -> 构建、执行、部署

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM