Search code examples
androidwebrtcquickblox

Getting Null pointer exception sometimes when creating QBRTCSession with opponents while making calls


Tried to implement webrtc audio/video call in my application using Quickblox SDK version 2.2.1. Implemented QBRTCClientCallback interface on an Android Service Class. Able to make audio/video calls, but consistency is the issue. I'm able to make audio/video calls, but consistency is the issue . Getting NullPointerException sometimes when creating session with opponents while making calls.

Following is the code:

QBRTCSession newSessionWithOpponents = QBRTCClient.getInstance().createNewSessionWithOpponents(opponents, qbConferenceType);

I'm getting values for QBRTCClient.getInstance(),opponents, and qbConferenceType.

How can we solve this issue? Do we have any alternate method to create session rather than createNewSessionWithOpponents? Is this because of implementing QBRTCClientCallback interface on Android Service Class?


Solution

  • QBRTCClient.getInstance().getActivity() sometimes becomes null and you wont be able to create session in that case since createNewSessionWithOpponents method uses QBRTCClient.getInstance().getActivity()

    Try adding below code before creating session

    if(QBRTCClient.getInstance().getActivity() == null) {
               QBRTCClient.init((Activity) context);
               QBRTCClient.getInstance().setActivity((Activity)context);
       }
    

    :)