2013-04-18 73 views
2

我正在開發一個使用ASMACK的聊天應用程序,我可以連接和發送私人聊天消息。但是,當試圖創建聊天室我得到的錯誤:在Android中創建聊天室給出錯誤:「item-not-found(404)

 item-not-found(404) 

這是我使用的代碼:

  setConnection(connection); 
      if(connection != null) 
      { 
       try 
     { 
       // SmackAndroid.init(this); 
       MultiUserChat muc=new MultiUserChat(connection,"[email protected]"); 
       muc.create("greatandroid"); 
       Log.d("Chat Room Created","Successfully Created Chat Room"); 
       Form form = muc.getConfigurationForm(); 
       Form submitForm = form.createAnswerForm(); 
       for (Iterator fields = form.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); 
         muc.sendConfigurationForm(submitForm); 
         Log.d("Config Form Created","Successfully Configured Chat Form"); 
        } 
       }  

       } 
       catch(Exception ex) 
       {Log.d("Error Creating Chat Room",ex.getMessage().toString());}} 

我怎樣才能解決這個

回答

0

使用此代碼

// Get the the room's configuration form 
      Form form = muc.getConfigurationForm(); 
      // Create a new form to submit 
      // based on the original form 
      Form submitForm = form.createAnswerForm(); 
      // Add default answers to the form 
      // to submit 
      for (Iterator fields = form.getFields(); fields.hasNext();) { 
       FormField field = (FormField) fields.next(); 
       if (!FormField.TYPE_HIDDEN.equals(field.getType()) 
         && field.getVariable() != null) { 
        // Sets the default value as 
        // the answer 
        // 

        submitForm.setDefaultAnswer(field.getVariable()); 
       } 
      } 


      submitForm.setAnswer("muc#roomconfig_roomdesc", GroupName); 
      submitForm.setAnswer("muc#roomconfig_publicroom", false); // 
      submitForm.setAnswer("muc#roomconfig_persistentroom", true); 
      // 
      submitForm.setAnswer("muc#roomconfig_membersonly", false); 
      // 
      submitForm.setAnswer("muc#roomconfig_allowinvites", true); 
      // JID 
      // submitForm.setAnswer("muc#roomconfig_whois", "anyone"); 
      // 
      submitForm.setAnswer("muc#roomconfig_enablelogging", true); 
      // 
      // submitForm.setAnswer("x-muc#roomconfig_reservednick", true); 
      // 
      // submitForm.setAnswer("x-muc#roomconfig_canchangenick", 
      // false); 
      // 
      // submitForm.setAnswer("x-muc#roomconfig_registration", false); 
      // Send the completed form (with default values) to the 
      // server to configure the room 
      muc.sendConfigurationForm(submitForm);