gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 17:01:22 24 4
gpt4 key购买 nike

我正在尝试在私有(private)对话中发送短信,在我创建私有(private)对话之前一切正常,但是当我发送短信时我收到此错误“尝试调用虚拟方法'void com.quickblox.chat.QBAbstractChat.sendMessage (com.quickblox.chat.model.QBChatMessage)' 在空对象引用上”

@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) {

}
});

}

最佳答案

您必须在“qbChatDialog”模型而不是“对话框”上调用方法 sendMessage(..),或者您必须使用 dialog.initForChat(QBChatService.getInstance()); 初始化“对话框”以进行聊天在发送消息之前。参见 QuickBlox documentation

关于android - QUICKBLOX 尝试在空对象引用上调用虚拟方法 sendMessage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42738236/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com