我被困在创建一个私人创建聊天对话框。我正在尝试为id 19创建静态私人聊天对话框。
我在PrivateChatManager上得到空对象引用
public class ChattingFragment extends Fragment {
public static final String APP_ID = "*****";
public static final String AUTH_KEY = "********";
public static final String AUTH_SECRET = "*********";
public static final String ACCOUNT_KEY = "*************";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_chatting, container, false);
QBSettings.getInstance().init(getActivity(), APP_ID, AUTH_KEY, AUTH_SECRET);
QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);
loginForQuickBlox();
QBAuth.createSession(new QBEntityCallback<QBSession>() {
@Override
public void onSuccess(QBSession session, Bundle params) {
Toast.makeText(getActivity(), "Sucess session", Toast.LENGTH_LONG).show();
}
@Override
public void onError(QBResponseException errors) {
Toast.makeText(getActivity(), "error session" + errors.getMessage(), Toast.LENGTH_LONG).show();
}
});
return rootView;
}
private boolean loginForQuickBlox() {
final QBUser user = new QBUser();
user.setEmail("emailid@email.com");
user.setPassword("123456789");
QBUsers.signIn(user, new QBEntityCallback<QBUser>() {
@Override
public void onSuccess(QBUser users, Bundle params) {
Toast.makeText(getActivity(), "Sucess login" + users.getId(), Toast.LENGTH_LONG).show();
/**here i have to create static dialog for chat with id 19 **/
QBChatService chatService = QBChatService.getInstance();
QBPrivateChatManager privateChatManager = chatService.getPrivateChatManager();
privateChatManager.createDialog(19, new QBEntityCallbackImpl<QBDialog>() {
@Override
public void onSuccess(QBDialog dialog, Bundle args) {
}
});
}
@Override
public void onError(QBResponseException errors) {
Toast.makeText(getActivity(), errors.getMessage(), Toast.LENGTH_LONG).show();
}
});
return true;
}
}
下面是我的日志。
AndroidRuntime: FATAL EXCEPTION: main
Process: com.archi.intrisfeed, PID: 24211
java.lang.NullPointerException: Attempt to invoke virtual method 'com.quickblox.core.QBRequestCanceler com.quickblox.chat.QBPrivateChatManager.createDialog(int, com.quickblox.core.QBEntityCallback)' on a null object reference
at com.archi.intrisfeed.fragment.ChattingFragment$3.onSuccess(ChattingFragment.java:102)
at com.archi.intrisfeed.fragment.ChattingFragment$3.onSuccess(ChattingFragment.java:96)
at com.quickblox.core.Query.notifySuccess(Query.java:372)
at com.quickblox.core.Query$VersionEntityCallback.completedWithResponse(Query.java:404)
at com.quickblox.core.Query.completedWithResponse(Query.java:277)
at com.quickblox.core.server.HttpRequestRunnable$1.handleMessage(HttpRequestRunnable.java:42)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
10-18 12:55:54.181 1224-1224/? E/libEGL: called unimplemented OpenGL ES API
在创建对话框之前,您应该登录到聊天(如果您使用QuickBlox Android SDK版本2.6.1或更早),请参阅链接。从3.0版本开始,您可以使用类QBRestChatService创建对话框,详细信息通过链接
尝试使用quickblox从用户详细信息创建会话,然后登录用户进行聊天:
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
uNameStr = emailEdt.getText().toString();
uPwdStr = passwordEdt.getText().toString();
final QBUser user = new QBUser();
user.setEmail(uNameStr);
user.setPassword(uPwdStr);
createSession(user);
}
});
会话创建:
private void createSession(final QBUser user){
QBAuth.createSession(user,new QBEntityCallback<QBSession>() {
@Override
public void onSuccess(QBSession result, Bundle params) {
user.setId(result.getUserId());
loginForQuickBlox(user);
}
@Override
public void onError(QBResponseException e) {
e.printStackTrace();
createSession(user);
}
});
}
登录用户:
private boolean loginForQuickBlox(QBUser user) {
QBUsers.signIn(user, new QBEntityCallback<QBUser>() {
@Override
public void onSuccess(QBUser users, Bundle params) {
Toast.makeText(getActivity(), "Sucess login" + users.getId(), Toast.LENGTH_LONG).show();
QBChatService chatService = QBChatService.getInstance();
QBPrivateChatManager privateChatManager = chatService.getPrivateChatManager();
privateChatManager.createDialog(19, new QBEntityCallbackImpl<QBDialog>() {
@Override
public void onSuccess(QBDialog dialog, Bundle args) {
}
});
}
@Override
public void onError(QBResponseException errors) {
Toast.makeText(getActivity(), errors.getMessage(), Toast.LENGTH_LONG).show();
}
});
return true
}