Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在XMPP中,提交表单时未授权获取异常(401)_Java_Android_Xmpp - Fatal编程技术网

Java 在XMPP中,提交表单时未授权获取异常(401)

Java 在XMPP中,提交表单时未授权获取异常(401),java,android,xmpp,Java,Android,Xmpp,我可以添加组,但它显示“在确认配置之前,房间从入口被锁定”。我研究了一下,但没有找到满意的答案。下面是如何获得XMPP连接并提交表单的代码。发送表单时,它会抛出“未授权异常” xmppConnection = connectionThread.getXMPPConnection(); if (xmppConnection == null) { Application.getInstance().onError(R.string.NOT_CONNECTED);

我可以添加组,但它显示“在确认配置之前,房间从入口被锁定”。我研究了一下,但没有找到满意的答案。下面是如何获得XMPP连接并提交表单的代码。发送表单时,它会抛出“未授权异常”

xmppConnection = connectionThread.getXMPPConnection();
    if (xmppConnection == null) {
        Application.getInstance().onError(R.string.NOT_CONNECTED);
        return;
    }
    final MultiUserChat multiUserChat;
    try {

        multiUserChat = new MultiUserChat(xmppConnection, room);
    //  setConfig(multiUserChat);

    } catch (IllegalStateException e) {
        Application.getInstance().onError(R.string.NOT_CONNECTED);
        return;
    }
//提交表单的代码

private void setConfig(MultiUserChat multiUserChat) {

    try {
        Form form = multiUserChat.getConfigurationForm();
        Form submitForm = form.createAnswerForm();
        for (Iterator<FormField> fields = submitForm.getFields(); fields
                .hasNext();) {
            FormField field = (FormField) fields.next();
            if (!FormField.TYPE_HIDDEN.equals(field.getType())
                    && field.getVariable() != null) {
                submitForm.setDefaultAnswer(field.getVariable());
            }
        }
        submitForm.setAnswer("muc#roomconfig_publicroom", true);
        submitForm.setAnswer("muc#roomconfig_persistentroom", true);
        multiUserChat.sendConfigurationForm(submitForm);
    } catch (Exception e) {
        e.printStackTrace();
    }

}
private void setConfig(多用户聊天多用户聊天){
试一试{
Form Form=multiUserChat.getConfigurationForm();
Form submitForm=Form.createAnswerForm();
for(迭代器字段=submitForm.getFields();字段
.hasNext();){
FormField=(FormField)fields.next();
如果(!FormField.TYPE_HIDDEN.equals(field.getType())
&&field.getVariable()!=null){
submitForm.setDefaultAnswer(field.getVariable());
}
}
submitForm.setAnswer(“muc#roomconfig_publicroom”,true);
submitForm.setAnswer(“muc#roomconfig_persistentroom”,true);
multiUserChat.sendConfigurationForm(submitForm);
}捕获(例外e){
e、 printStackTrace();
}
}

为了回答这个问题,我只是修改了你的评论


您正在调用
setConfig()。应该在加入组后调用。

问题现在已经解决,我从错误的位置调用了setConfig()方法。应该在加入团体后再打电话。多用户聊天。加入(昵称、密码);//为文件室设置默认配置setDefaultConfig(multiUserChat);你可以回答自己的问题并接受它。:)