【发布时间】:2017-03-14 20:30:24
【问题描述】:
我正在尝试在私人对话中发送短信,在我创建私人对话之前一切正常,但是当我发送短信时,我收到此错误“尝试调用虚拟方法'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) {
}
});
}
}
【问题讨论】: