So it's about getting,
java.lang.NullPointerException
while using Twilio programable chat SDK in Android
I have one fragment where I am getting the list of the channel, On the click of the particular channel I am passing the channel sid from fragment to activity and in the activity, I am getting the channel from client again by using that sid, but when I am trying to get last messages from the channel then I am getting
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.twilio.chat.Messages.getLastMessages(int, com.twilio.chat.CallbackListener)' on a null object reference
And the mystery is When I use "attach a debugger to the android process", I can see the error I can get object and messages also with debugger on. I believe this is something to do with threading.
Here is the code
myChannel.getMessages().getLastMessages(50, new CallbackListener<List<Message>>() {
@Override
public void onSuccess(List<Message> messages) {
mMessagesAdapter.setMessages(mMessages);
setMessageInputEnabled(true);
mWriteMessageEditText.requestFocus();
}
@Override
public void onError(ErrorInfo errorInfo) {
Log.e(TAG, "error" + errorInfo.getMessage());
}
});
Also, I came to know with the doc of Twilio that, I have to use synchronized method over the Channel object. with the method "myChannel.getMessages()". doc-link: URL I am attaching a screenshot: enter image description here
And I believe I have to do synchronization first with using some method, but I do not see any method for that. How can I synchronize? What code Should I use?
Please help me. Thanks in advance