title: App Crashing while adding a member in an Private channel in Twilio Chat SDK
body: <p>I am implementing Twilio Chat SDK where I do add members in a private Channel. The flow goes like this that First I check whether is there a channel in my list or not. If it exists then I join it. And if there is no channel in my list I First create it and then join and it and then add member with it's unique name. When I run my application the Client is created and after the channel process is done it crashes with the following error:</p>
  <pre><code>com.twilio.chat.ListenerException: Exception thrown by a listener. Your application might have a problem in listener implementation. Listeners must never throw uncaught exceptions. See 'Caused by:' below for more details.
          at java.lang.reflect.Constructor.newInstance0(Native Method)
          at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
          at com.twilio.chat.internal.RethrowingForwarder$RethrowingProxy.invoke(RethrowingForwarder.java:123)
          at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
          at $Proxy17.onError(Unknown Source)
          at com.twilio.chat.internal.StatusListenerForwarder$2.run(StatusListenerForwarder.java:46)
          at android.os.Handler.handleCallback(Handler.java:883)
          at android.os.Handler.dispatchMessage(Handler.java:100)
          at android.os.Looper.loop(Looper.java:237)
          at android.app.ActivityThread.main(ActivityThread.java:8167)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
       Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.twilio.chat.Members.addByIdentity(java.lang.String, com.twilio.chat.StatusListener)' on a null object reference
          at com.zofeur.customer.views.fragments.SupportFragment.addMemberInChannel(SupportFragment.kt:259)
          at com.zofeur.customer.views.fragments.SupportFragment.access$addMemberInChannel(SupportFragment.kt:22)
          at com.zofeur.customer.views.fragments.SupportFragment$joinChannel$1.onError(SupportFragment.kt:249)
  </code></pre>
  <p>I have been looking for several solutions but unable to do so.</p>
  <p>Below is the code for my Fragment:</p>
  <p>Support Fragment:</p>
  <pre><code>private fun createChannel(channelUniqueName: String) {
      mViewModel.chatClient?.channels?.getChannel(channelUniqueName,
          object : CallbackListener&lt;Channel&gt;() {
              override fun onSuccess(channel: Channel?) {
                  if (channel != null) {
                      mViewModel.channel = channel
                      joinChannel(channel)
  
                  }
              }
  
              override fun onError(errorInfo: ErrorInfo?) {
                  super.onError(errorInfo)
                  if (errorInfo?.code == Constants.ERROR_CHANNEL_NOT_FOUND) {
                      mViewModel.chatClient?.channels?.channelBuilder()
                          ?.withUniqueName(channelUniqueName)
                          ?.withType(Channel.ChannelType.PRIVATE)
                          ?.build(object : CallbackListener&lt;Channel&gt;() {
                              override fun onSuccess(channel: Channel?) {
                                  requireContext().T(&quot;Channel Created $channel&quot;)
                                  if (channel != null) {
                                      mViewModel.channel = channel
                                      joinChannel(channel)
                                  }
                              }
  
                          })
                  } else {
                      requireContext().T(&quot;Channel not created&quot; + errorInfo.toString())
  
                  }
              }
          })
  
  }
  
  private fun joinChannel(channel: Channel) {
      channel.join(object : StatusListener() {
          override fun onSuccess() {
              requireContext().T(&quot;Channel Joined&quot; + channel.uniqueName)
              addMemberInChannel(channel, identity)
          }
  
          override fun onError(errorInfo: ErrorInfo) {
              if (errorInfo.code == Constants.ERROR_MEMBER_ALREADY_EXISTS) {
                  // already join member
                  addMemberInChannel(channel, identity)
              } else {
                  requireContext().T(&quot;Error joining channel$errorInfo&quot;)
              }
          }
      })
  }
  
  private fun addMemberInChannel(channel: Channel, identity: String) {
      if (mViewModel.channel.createdBy == mViewModel.chatClient.myIdentity) {
          channel.members.addByIdentity(identity, object : StatusListener() {
              override fun onSuccess() {
                  requireContext().T(&quot;Member added successfully&quot; + channel.uniqueName)
              }
  
              override fun onError(errorInfo: ErrorInfo?) {
                  super.onError(errorInfo)
                  requireContext().T(&quot;Channel member added error&quot; + errorInfo.toString())
              }
          })
  
      } else {
          requireContext().T(&quot;You cannot add member, You don't have rights.&quot;)
      }
  }
  </code></pre>
  <p>Any sort of help would be very helpful. Thanks in advance.</p>