【问题标题】:Android WebRTC crashes during the second time I run the WebRTC ActivityAndroid WebRTC 在我第二次运行 WebRTC Activity 时崩溃
【发布时间】:2019-01-18 16:06:27
【问题描述】:

我正在制作一个可以通过 WebRTC 进行视频通话的应用。 在第一次调用 Activity for WebRTC 时,一切运行顺利,但在第二次时,由于我的 localPeer 对象上的空指针异常,我遇到了崩溃:

    java.lang.NullPointerException: Attempt to invoke virtual method 'void org.webrtc.PeerConnection.setRemoteDescription(org.webrtc.SdpObserver, org.webrtc.SessionDescription)' on a null object reference

在完成活动之前,我已经尝试清理 onDestroy 的资源:

  if (localPeer != null) {
            localPeer.close();
            localPeer.dispose();
        }

我在清理可能导致崩溃的资源方面做错了吗?或者是什么导致peerConnectionFactory.createPeerConnection() 返回null?

【问题讨论】:

标签: android webrtc


【解决方案1】:

好的,我发现了这个问题。

我有一个客户端类,它充当我的 Socket.IO 连接的包装器。我们称它为ClientClass。在 ClientClass 中,我有一个私有静态 ClientClass 实例,只能通过调用类的静态 getInstance() 方法来访问。

在关闭连接期间,我忘记将其设置为 null:

  public void close() {
    socket.emit("bye");
    socket.off();
    socket.disconnect();
    socket.close();
    roomName = null;
    socket = null;
    instance = null; //I forgot this line
}

这是一个非常奇怪的问题,很难从错误中调试,无法仅通过读取错误日志来跟踪。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    相关资源
    最近更新 更多