使用UserSearchManager时,Form#setAnswer(“Username”,true)中的XMPP IIllegalArgumentException

时间:2014-08-20 16:05:03

标签: android xmpp chat ejabberd

我正在使用ejabberd 2.1.11开发android聊天应用程序。用于搜索特定用户是否存在我正在使用UserSearchManager

public boolean isUserExists(IrishContact ic) {
        try {
            UserSearchManager search = new UserSearchManager(connection);
            Collection<String> services = search.getSearchServices();
            if (services.isEmpty()) {
                Log.v("IrishuserSearch ", "no service found");
            }

            Log.v("service name: ", connection.getServiceName());

            Form searchForm = search.getSearchForm("vjud."
                    + connection.getServiceName());

            Form answerForm = searchForm.createAnswerForm();
            answerForm.setAnswer("Username", true);
            answerForm.setAnswer("search", ic.getPhoneNumber());
            org.jivesoftware.smackx.ReportedData data = search
                    .getSearchResults(answerForm,
                            "search." + connection.getServiceName());

            if (data.getRows() != null) {
                Iterator<Row> it = data.getRows();
                if (it.hasNext()) {
                    return true;
                } else
                    return false;
            } else
                return false;

        } catch (XMPPException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;

    }

基于this回答

我正在使用

  

表单searchForm = search.getSearchForm(“vjud”。                     + connection.getServiceName());

而不是

  

表格searchForm =   search.getSearchForm( “搜索”。+ connection.getServiceName());

后面部分给出了503服务未找到异常所以我改变了我的代码并且它得到了解决,但现在问题是我在

获得了IllegalArgumentException
  

answerForm.setAnswer(“Username”,true);

我正在使用asmack-android-8-0.8.10。

STACK_TRACE=java.lang.IllegalArgumentException: Field not found for the specified variable name.
at org.jivesoftware.smackx.Form.setAnswer(Form.java:258)
at com.irishtalk.utilities.IrishUserSearch.isUserExists(IrishUserSearch.java:42)

at com.irishtalk.utilities.IrishContactsHelper.addContactToDefaultRoster(IrishContactsHelper.java:51)
at com.irishtalk.utilities.IrishContactsHelper.getRoster(IrishContactsHelper.java:32)
at com.irishtalk.service.IXmppAidlStub$1.run(IXmppAidlStub.java:221)

任何人都可以帮助我解释为什么会这样吗?感谢

1 个答案:

答案 0 :(得分:0)

Ejabberd不支持字段值&#34;用户名&#34;。它用于openfire。请使用字段值&#34; user&#34;并在ejabberd中将参数作为字符串传递。谢谢。如果您的错误已经解决,请投票。