通过 Asmack 阻止用户,我得到 NULL 指针 Execption 我阅读了 privacymanager 文档,但我不知道为什么我得到这个 NullPointerException 有什么问题,请注意连接很好,我可以发送和接收任何人都可以的消息帮助
public void blockContact(String user) {
try {
PrivacyListManager privacyManager = PrivacyListManager
.getInstanceFor(MyApplication.connection);
// Set the name of the list
String listName = "blocklist1";
// Create the list of PrivacyItem that will allow or deny some
// privacy aspect
//
List<PrivacyItem> privacyItems = new Vector<PrivacyItem>();
PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid.name(),
false, 1);
item.setValue(user);
item.setFilterMessage(true);
privacyItems.add(item);
Log.d(getLocalClassName() + "isFilterMessage : ",
item.isFilterMessage() + "");
privacyManager.createPrivacyList(listName, privacyItems); //HERE
privacyManager.addListener(this); // AND HERE
} catch (Exception e) {
e.printStackTrace();
}
}
错误:
10-05 11:51:16.649: W/System.err(25166): java.lang.NullPointerException
10-05 11:51:16.649: W/System.err(25166): at com.app.chat.MyChat.blockContact(MyChat.java:807)