2

I am stuck creating a private create chat dialog. I am trying to create static private chat dialog for id 19.

I am getting null object reference on 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;
    }
}

Below is my logcat.

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
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Raj Gohel
  • 524
  • 6
  • 11

2 Answers2

1

you should be logged in to the chat before creating dialog (if you use QuickBlox Android SDK version 2.6.1 or older) please see link. From version 3.0 you can create dialog using the class QBRestChatService, details by link

0

Try create session with quickblox from user details and then login user for chat:

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

Session creation :

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

Login 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
}
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
  • I have implement this code also but still getting the same above logcat. so please guide me whats going wrong ? – Raj Gohel Oct 18 '16 at 07:30