You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XMPP即时房间创建成功但加入失败(item-not-found错误)求助

Fixing the XMPP item-not-found Error When Joining an Invited MUC Room

Hey Rahul, let's break down what's causing that frustrating XMPPError: item-not-found - cancel error and get your MUC room joins working properly.

First, Let's Diagnose the Key Issues in Your Code

From looking at your implementation, there are a couple of critical missteps that are likely triggering the error:

1. Incorrect Instant Room Creation Flow

Your current code submits configuration forms twice, which can corrupt the room's setup and lead to it being unrecognizable later:

// This first submit applies owner settings
muc.create(nickname)
  .getConfigFormManager()
  .setRoomOwners(owners)
  .submitConfigurationForm();
// This second empty submit overrides/conflicts with the first
muc.sendConfigurationForm(new Form(DataForm.Type.submit));

Instant rooms only need a single configuration submission. Submitting twice can leave the room in an inconsistent state.

2. Invalid Nickname in the Invite Listener

You're using the entire room JID as a nickname when joining, which is not valid:

Resourcepart nickname = Resourcepart.from(room.getRoom().toString());

Nicknames should be a simple user alias (like your username), not the full room identifier. This invalid nickname can cause the server to reject the join request as it can't map it to a valid participant.

Step-by-Step Fixes

Fix 1: Correct the Instant Room Creation

Rewrite your room creation code to handle configuration properly without duplicate submissions:

// Get the MultiUserChatManager
manager = MultiUserChatManager.getInstanceFor(Utils.connection);
// Get a MultiUserChat using MultiUserChatManager
MultiUserChat muc = manager.getMultiUserChat(mucJid);

try {
    // Create the room with your nickname
    muc.create(nickname);
    
    // Fetch the default configuration form
    Form defaultForm = muc.getConfigFormManager().getConfigurationForm();
    // Create a submit form from the default template
    Form submitForm = defaultForm.createAnswerForm();
    
    // Set room owners if needed (add this only if you require custom owners)
    submitForm.setAnswer("muc#roomconfig_roomowners", Arrays.asList("54321@rahul", "12345@rahul"));
    
    // Submit the form to finalize the instant room
    muc.getConfigFormManager().submitConfigurationForm(submitForm);
    
    // Join the room immediately after creation
    muc.join(nickname);
    
    // Send your invite
    EntityBareJid invitemucJid = JidCreate.entityBareFrom("12345@rahul");
    muc.invite(invitemucJid, "testing");
} catch (Exception e) {
    e.printStackTrace();
}

This ensures the room is created with a consistent configuration, no duplicate submissions, and you're properly joined as the creator.

Fix 2: Use a Valid Nickname in the Invite Listener

Replace the invalid room-JID nickname with a proper user alias:

try {
    // Use a valid, user-specific nickname (e.g., your username or a custom alias)
    Resourcepart userNickname = Resourcepart.from("rahul_user"); // Replace with actual user nickname
    // Alternative: Pull from the current user's JID resource
    // Resourcepart userNickname = Utils.connection.getUser().getResourceOrEmpty();
    
    room.join(userNickname);
    Log.d(TAG, "room status---> " + room.isJoined());
    
    runOnUiThread(() -> {
        String toastMsg = room.isJoined() ? "Joined successfully!" : "Failed to join room";
        Toast.makeText(FriendListActivity.this, toastMsg, Toast.LENGTH_SHORT).show();
    });
} catch (Exception e) {
    e.printStackTrace();
}

Additional Checks to Rule Out Edge Cases

  • Verify MUC Service Domain: Ensure services.get(0) returns a valid MUC service domain (e.g., conference.yourserver.com). A wrong domain will create a room that doesn't actually exist on the server.
  • Confirm Room Existence: After creation, log the room JID and check if it appears in your server's MUC service list (via server admin tools if available).
  • Validate Invitee JID: Double-check that 12345@rahul is the correct bare JID of the user you're inviting—typos here can lead to failed joins.

内容的提问来源于stack exchange,提问作者Rahul Agrawal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:52:26