Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android QUICKBLOX尝试在空对象引用上调用虚拟方法sendMessage_Android_Quickblox - Fatal编程技术网

Android QUICKBLOX尝试在空对象引用上调用虚拟方法sendMessage

Android QUICKBLOX尝试在空对象引用上调用虚拟方法sendMessage,android,quickblox,Android,Quickblox,我试图在private dialog中发送文本消息,在创建private dialog之前一切正常,但当我发送文本消息时,在空对象引用上出现以下错误“尝试调用虚拟方法'void com.quickblox.chat.QBAbstractChat.sendMessage(com.quickblox.chat.model.QBChatMessage)” @覆盖 创建时受保护的void(Bundle savedInstanceState){ 最终上下文=此; super.onCreate(savedI

我试图在private dialog中发送文本消息,在创建private dialog之前一切正常,但当我发送文本消息时,在空对象引用上出现以下错误“尝试调用虚拟方法'void com.quickblox.chat.QBAbstractChat.sendMessage(com.quickblox.chat.model.QBChatMessage)”

@覆盖
创建时受保护的void(Bundle savedInstanceState){
最终上下文=此;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
QBSettings.getInstance().init(getApplicationContext(),APP\u ID,AUTH\u KEY,AUTH\u SECRET);
QBSettings.getInstance().setAccountKey(帐户密钥);
QBChatService.setDebugEnabled(true);
final QBChatService chatService=QBChatService.getInstance();
最终QBUser QBUser=新QBUser(“shahzeb”、“shahzeb143”);
createSession(qbUser).performAsync(新的QBEntityCallback(){
@凌驾
成功时公共无效(QBSession QBSession,Bundle Bundle){
setId(qbSession.getUserId());
登录(qbUser,新的QBEntityCallback(){
@凌驾
成功时的公共void(对象o,Bundle){
最终QBChatDialog=DialogUtils.buildPrivateDialog(25024405);
createChatDialog(dialog).performAsync(新的QBEntityCallback(){
@凌驾
成功时公共无效(QBChatDialog QBChatDialog,捆绑包){
QBChatMessage chatMessage=新的QBChatMessage();
setSenderId(qbUser.getId());
chatMessage.setBody(“你好!”);
试一试{
dialog.sendMessage(chatMessage);
}捕捉(SmackException.NotConnectedException e){
e、 printStackTrace();
}
}
@凌驾
公共无效报告人(QBResponseException e){
}
});
}
@凌驾
公共无效报告人(QBResponseException e){
}
});
}
@凌驾
公共无效报告人(QBResponseException e){
}
});
}

}

您必须调用'qbChatDialog'模型上的方法sendMessage(..),而不是'dialog',或者必须使用dialog.initForChat(QBChatService.getInstance())初始化'dialog'进行聊天;在发送消息之前。看

@Override
protected void onCreate(Bundle savedInstanceState) {

    final Context context = this;

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    QBSettings.getInstance().init(getApplicationContext(), APP_ID, AUTH_KEY, AUTH_SECRET);
    QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);

    QBChatService.setDebugEnabled(true);
    final QBChatService chatService = QBChatService.getInstance();
    final QBUser qbUser = new QBUser("shahzeb", "shahzeb143");
    QBAuth.createSession(qbUser).performAsync(new QBEntityCallback<QBSession>() {
        @Override
        public void onSuccess(QBSession qbSession, Bundle bundle) {
            qbUser.setId(qbSession.getUserId());


            chatService.login(qbUser, new QBEntityCallback() {
                @Override
                public void onSuccess(Object o, Bundle bundle) {


                    final QBChatDialog dialog = DialogUtils.buildPrivateDialog(25024405);
                    QBRestChatService.createChatDialog(dialog).performAsync(new QBEntityCallback<QBChatDialog>() {
                        @Override
                        public void onSuccess(QBChatDialog qbChatDialog, Bundle bundle) {

                            QBChatMessage chatMessage = new QBChatMessage();
                            chatMessage.setSenderId(qbUser.getId());
                            chatMessage.setBody("Hi there!");
                            try {
                                dialog.sendMessage(chatMessage);
                            } catch (SmackException.NotConnectedException e) {
                                e.printStackTrace();
                            }
                        }

                        @Override
                        public void onError(QBResponseException e) {

                        }
                    });
                }

                @Override
                public void onError(QBResponseException e) {

                }
            });
        }

        @Override
        public void onError(QBResponseException e) {

        }
    });

}