'void com.quickblox.chat.QBAbstractChat.sendMessage 空对象引用

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

我正在使用 Quickblox sdk 将聊天功能集成到我的应用程序中。

我已经创建了 Quickblox Session 并且还登录了用户 "Chat Service"。 但是,当我尝试向 "Recipent" 发送消息时,应用程序崩溃,抛出以下异常:

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

下面是我的代码:

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


    }

这里的问题是,“Quickblox”经常发生。有时用户会自动退出 quickblox,因此会抛出此类异常。因此,请确保您 "Logged in" 到 quickblox 服务器。另外,请检查您的 qbChatDialog。它可能不为空,但请检查存储在包中的值。