我正在尝试使用quickblox在android中创建一个聊天应用程序演示,我成功地获得了一个用户列表,并且在单击usrlist时,我得到了它的“ id”,我将其传递给创建新的聊天对话框代码,但是它给了我Nullpointer在privatechatmanager。

我的代码是:

   public Integer getOpponentIDForPrivateDialog(QBDialog dialog){
        Integer opponentID = -1;
        for(Integer userID : dialog.getOccupants()){
            if(!userID.equals(getCurrentUser().getId())){
                opponentID = userID;
                break;
            }
        }
        return opponentID;
    }


日志猫
06-16 17:11:07.817:

 I/System.out(32408): =============MY SELECTED USER==============3588999
06-16 17:11:07.847: D/AndroidRuntime(32408): Shutting down VM
06-16 17:11:07.847: W/dalvikvm(32408): threadid=1: thread exiting with uncaught exception (group=0x418a3da0)
06-16 17:11:07.847: E/AndroidRuntime(32408): FATAL EXCEPTION: main
06-16 17:11:07.847: E/AndroidRuntime(32408): Process: com.amar.chums, PID: 32408
06-16 17:11:07.847: E/AndroidRuntime(32408): java.lang.NullPointerException
06-16 17:11:07.847: E/AndroidRuntime(32408):    at com.amar.chums.activity.ManageConnection$2.onItemClick(ManageConnection.java:154)
06-16 17:11:07.847: E/AndroidRuntime(32408):    at android.widget.AdapterView.performItemClick(AdapterView.java:313)
06-16 17:11:07.847: E/AndroidRuntime(32408):    at android.widget.AbsListView.performItemClick(AbsListView.java:1507)
06-16 17:11:07.847: E/AndroidRuntime(32408):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:3514)
06-16 17:11:07.847: E/AndroidRuntime(32408):    at android.widget.AbsListView$3.run(AbsListView.java:5072)
06-16 17:11:07.847: E/AndroidRuntime(32408):    at android.os.Handler.handleCallback(Handler.java:733)
06-16 17:11:07.847: E/AndroidRuntime(32408):    at android.os.Handler.dispatchMessage(Handler.java:95)
06-16 17:11:07.847: E/AndroidRuntime(32408):    at android.os.Looper.loop(Looper.java:146)
06-16 17:11:07.847: E/AndroidRuntime(32408):    at android.app.ActivityThread.main(ActivityThread.java:5653)
06-16 17:11:07.847: E/AndroidRuntime(32408):    at java.lang.reflect.Method.invokeNative(Native Method)
06-16 17:11:07.847: E/AndroidRuntime(32408):    at java.lang.reflect.Method.invoke(Method.java:515)
06-16 17:11:07.847: E/AndroidRuntime(32408):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
06-16 17:11:07.847: E/AndroidRuntime(32408):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
06-16 17:11:07.847: E/AndroidRuntime(32408):    at dalvik.system.NativeStart.main(Native Method)


请帮助我救我的命.. !!!

最佳答案

尝试处理nullpointer

my_list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            System.out
                    .println("=============MY SELECTED USER=============="
                            + myConnections.get(position).get("id"));
            QBDialog dialog = new QBDialog();
            dialog.setType(QBDialogType.PRIVATE);

            QBPrivateChatManager privateChatManager = QBChatService
                    .getInstance().getPrivateChatManager();

            // try to handle the null value of both object
            // i just discontinue the further code by returning the method ..do as per your requirement
            // try to re-instialize or find the case..why its happen
            if(privateChatManager == null || myConnections == null)
                return;

            privateChatManager.createDialog(
                    Integer.parseInt(myConnections.get(position).get("id")),
                    new QBEntityCallbackImpl<QBDialog>() {
                        @Override
                        public void onSuccess(QBDialog dialog, Bundle args) {

                        }

                        @Override
                        public void onError(List<String> errors) {

                        }
                    });
        }
    });

07-28 04:00