2013-03-06 38 views
1

在XMPP中,当我向其他用户发送好友请求时,如果其他用户想拒绝它,则应从名单中删除条目,但我无法删除条目来自用户。这是给我强制关闭(与空指针异常)在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("[email protected]"); 
      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被赋予空指针;

感谢

回答

1

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

从规格:

注意:如果联系人的服务器之前添加的用户联系人的名册用于跟踪目的,它必须在此时间删除相关项目。

您可以阅读更多here

+0

但没有状态的名单项目根本没有删除,而是它在RosterEntry给我空指针异常。 谢谢 – 2013-03-06 09:42:58