【问题标题】:Denying Request in Xmpp - Remove Entry from roster拒绝 Xmpp 中的请求 - 从名册中删除条目
【发布时间】:2013-03-06 07:50:54
【问题描述】:

在 XMPP 中,当我向其他用户发送好友请求时,如果其他人想要拒绝它,则应该删除名册中的条目,但我无法删除用户的条目。它给了我强制关闭(空指针异常)

这是我的拒绝按钮代码

btn_Deny = (Button)findViewById(R.id.btn_manageNotification_DENY);
        btn_Deny.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Presence unsubscribe = new Presence(Presence.Type.unsubscribed);
                unsubscribe.setTo(id);              
                connection.sendPacket(unsubscribe);

                /*String message = mXmconn.removeFriend(subID, CMMStaticVariable.CommonConnection);
                System.out.println(message);*/

                Intent returnBack = new Intent(ManageNotification.this, UserMenuActivity.class);
                startActivity(returnBack);
                finish();               
            }
        });     
    }

删除好友

public String removeFriend(String jid, XMPPConnection connection){
        roster = connection.getRoster();
        String message = "";
        try {
            RosterEntry rosterEntry = roster.getEntry("chamak@abec.info.com");
            System.out.println("rosterEntryy"+rosterEntry.toString());

            roster.removeEntry(rosterEntry);
            message = "You have denied the friend request";
        } catch (XMPPException e) {
            e.printStackTrace();
            message = "Exception";
        }
        return message;
    }

它在 rosterEntry = null 处给出空指针;

谢谢

【问题讨论】:

    标签: android xmpp


    【解决方案1】:

    XMPP-CORE 定义服务器在拒绝订阅请求时必须从用户名册中删除名册项。因此,当您尝试请求时,该项目甚至不应该存在。

    来自规范:

    注意:如果联系人的服务器之前将用户添加到联系人的名册以进行跟踪,则此时必须删除相关项目。

    您可以阅读更多here

    【讨论】:

    • 但是没有状态的名册项根本没有删除,而是在名册条目处给了我空指针异常。谢谢
    猜你喜欢
    • 2018-04-03
    • 1970-01-01
    • 1970-01-01
    • 2018-11-12
    • 1970-01-01
    • 2011-10-24
    • 1970-01-01
    • 2011-03-16
    • 2011-03-19
    相关资源
    最近更新 更多