0

I am using Quickblox sdk to integrate chat into my app.

I have created the Quickblox Session and also logged in user into "Chat Service". But, when I try to send a message to the "Recipent" the application crashes, throwing following exception:

Attempt to invoke virtual method 'void com.quickblox.chat.QBAbstractChat.sendMessage(com.quickblox.chat.model.QBChatMessage)' on a null object reference

Given below is my code:

    QBChatMessage chatMessage = new QBChatMessage();
    chatMessage.setBody(strMsg);
    chatMessage.setProperty(PROPERTY_SAVE_TO_HISTORY, "1");
    chatMessage.setDateSent(System.currentTimeMillis() / 1000);
    chatMessage.setMarkable(true);

     try {
        qbChatDialog.sendMessage(chatMessage);
    } catch (Exception e) {
        e.printStackTrace();


    }
Charuක
  • 12,229
  • 5
  • 43
  • 83
  • It is not a duplicate of this. This is a quickblox issue. I have cross checked the variables and objects that I am using. None of them are null. – Seasia Creative Crew Dec 28 '16 at 10:42
  • The variable `qbChatDialog` is definitely `null`. Check again! – David Wasser Dec 28 '16 at 10:55
  • 1
    It is not null. I rechecked it. – Seasia Creative Crew Dec 28 '16 at 11:06
  • Found the issue. So all those who are facing this issue, please take note. This happens with "Quickblox" alot. Sometimes the user is automatically logged out of quickblox, hence it throws this type of exception. So, Kindly make sure that you are "Logged in" to the quickblox server. Also, please check you qbChatDialog. It might not be null but, check the values that are stored in the bundle. – Seasia Creative Crew Dec 30 '16 at 10:58
  • Glad you were able to solve your problem! Please answer your own question and accept that answer. This will remove this question from the list of unanswered questions. – David Wasser Dec 30 '16 at 12:38

1 Answers1

3

The issue here is that, ithappens with "Quickblox" alot. Sometimes the user is automatically logged out of quickblox, hence it throws this type of exception. So, Kindly make sure that you are "Logged in" to the quickblox server. Also, please check you qbChatDialog. It might not be null but, check the values that are stored in the bundle.