'void com.quickblox.chat.QBAbstractChat.sendMessage on a null object reference

622 views Asked by At

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();


    }
1

There are 1 answers

0
Seasia Creative Crew On BEST ANSWER

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.