I am making an app that you can video call through WebRTC. On the first call to the Activity for WebRTC, everything runs smoothly, but on the second time, I get crashes due to Null Pointer exception on my localPeer object:
java.lang.NullPointerException: Attempt to invoke virtual method 'void org.webrtc.PeerConnection.setRemoteDescription(org.webrtc.SdpObserver, org.webrtc.SessionDescription)' on a null object reference
Before finishing the activity, I have tried clearing up the resources onDestroy as such :
if (localPeer != null) {
localPeer.close();
localPeer.dispose();
}
Am I doing anything wrong to clear up the resources that may cause the crash? Or what causes peerConnectionFactory.createPeerConnection()
to return null?