2013-09-25 48 views
2

嗨,我創建使用XMPP聊天應用中XMPP聊天程序錯誤。我的問題是,在運行出現一個對話框,顯示「你的項目中包含然後修正錯誤並運行」的項目,但沒有項目資源管理器中顯示錯誤,警告標誌是顯示(希望這不會影響rnuning項目)。控制檯頁面顯示如下:如何清除機器人

[2013-09-25 10:25:01 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/kenai/jbosh/AbstractAttr; 
[2013-09-25 10:25:01 - XMPPChatDemo] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/kenai/jbosh/AbstractAttr; 

我的程序代碼是:

public class XMPPChatDemoActivity extends Activity { 

    public static final String HOST = "192.168.1.4"; 
    public static final int PORT = 5222; 
    public static final String USERNAME = "semyma"; 
    public static final String PASSWORD = "computer"; 
    private XMPPConnection connection; 
    private ArrayList<String> messages = new ArrayList<String>(); 
    private Handler mHandler = new Handler(); 
    private EditText recipient; 
    private EditText textMessage; 
    private ListView listview; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     recipient = (EditText) this.findViewById(R.id.toET); 
     textMessage = (EditText) this.findViewById(R.id.chatET); 
     listview = (ListView) this.findViewById(R.id.listMessages); 
     setListAdapter(); 
     // Set a listener to send a chat text message 
     Button send = (Button) this.findViewById(R.id.sendBtn); 
     send.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       String to = recipient.getText().toString(); 
       String text = textMessage.getText().toString(); 
       Log.i("XMPPChatDemoActivity", "Sending text " + text + " to " + to); 
       Message msg = new Message(to, Message.Type.chat); 
       msg.setBody(text);    
       if (connection != null) { 
        connection.sendPacket(msg); 
        messages.add(connection.getUser() + ":"); 
        messages.add(text); 
        setListAdapter(); 
       } 
      } 
     }); 

     connect(); 
    } 

    /** 
    * Called by Settings dialog when a connection is establised with the XMPP 
    * server 
    * 
    * @param connection 
    */ 
    public void setConnection(XMPPConnection connection) { 
     this.connection = connection; 
     if (connection != null) { 
      // Add a packet listener to get messages sent to us 
      PacketFilter filter = new MessageTypeFilter(Message.Type.chat); 
      connection.addPacketListener(new PacketListener() { 
       @Override 
       public void processPacket(Packet packet) { 
        Message message = (Message) packet; 
        if (message.getBody() != null) { 
         String fromName = StringUtils.parseBareAddress(message 
           .getFrom()); 
         Log.i("XMPPChatDemoActivity", "Text Recieved " + message.getBody() 
           + " from " + fromName); 
         messages.add(fromName + ":"); 
         messages.add(message.getBody()); 
         // Add the incoming message to the list view 
         mHandler.post(new Runnable() { 
          public void run() { 
           setListAdapter(); 
          } 
         }); 
        } 
       } 
      }, filter); 
     } 
    } 

    private void setListAdapter() { 
     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
       R.layout.listitem, messages); 
     listview.setAdapter(adapter); 
    } 

    @Override 
    protected void onDestroy() { 
     super.onDestroy(); 
     try { 
      if (connection != null) 
       connection.disconnect(); 
     } catch (Exception e) { 

     } 
    } 

    public void connect() { 

     final ProgressDialog dialog = ProgressDialog.show(this, 
       "Connecting...", "Please wait...", false); 

     Thread t = new Thread(new Runnable() { 

      @Override 
      public void run() { 
       // Create a connection 
       ConnectionConfiguration connConfig = new ConnectionConfiguration(
         HOST, PORT); 
       XMPPConnection connection = new XMPPConnection(connConfig); 
       try { 
        connection.connect(); 
        Log.i("XMPPChatDemoActivity", 
          "Connected to " + connection.getHost()); 
       } catch (XMPPException ex) { 
        Log.e("XMPPChatDemoActivity", "Failed to connect to " 
          + connection.getHost()); 
        Log.e("XMPPChatDemoActivity", ex.toString()); 
        setConnection(null); 
       } 
       try { 
        // SASLAuthentication.supportSASLMechanism("PLAIN", 0); 
        connection.login(USERNAME, PASSWORD); 
        Log.i("XMPPChatDemoActivity", 
          "Logged in as " + connection.getUser()); 
        // Set the status to available 
        Presence presence = new Presence(Presence.Type.available); 
        connection.sendPacket(presence); 
        setConnection(connection); 
        Roster roster = connection.getRoster(); 
        Collection<RosterEntry> entries = roster.getEntries(); 
        for (RosterEntry entry : entries) { 
         Log.d("XMPPChatDemoActivity", 
           "--------------------------------------"); 
         Log.d("XMPPChatDemoActivity", "RosterEntry " + entry); 
         Log.d("XMPPChatDemoActivity", 
           "User: " + entry.getUser()); 
         Log.d("XMPPChatDemoActivity", 
           "Name: " + entry.getName()); 
         Log.d("XMPPChatDemoActivity", 
           "Status: " + entry.getStatus()); 
         Log.d("XMPPChatDemoActivity", 
           "Type: " + entry.getType()); 
         Presence entryPresence = roster.getPresence(entry 
           .getUser()); 
         Log.d("XMPPChatDemoActivity", "Presence Status: " 
           + entryPresence.getStatus()); 
         Log.d("XMPPChatDemoActivity", "Presence Type: " 
           + entryPresence.getType()); 
         Presence.Type type = entryPresence.getType(); 
         if (type == Presence.Type.available) 
          Log.d("XMPPChatDemoActivity", "Presence AVIALABLE"); 
         Log.d("XMPPChatDemoActivity", "Presence : " 
           + entryPresence); 

        } 
       } catch (XMPPException ex) { 
        Log.e("XMPPChatDemoActivity", "Failed to log in as " 
          + USERNAME); 
        Log.e("XMPPChatDemoActivity", ex.toString()); 
        setConnection(null); 
       } 

       dialog.dismiss(); 
      } 
     }); 
     t.start(); 
     dialog.show(); 
    } 
} 
+0

嘗試清潔工程 – WISHY

+0

刪除 「bin」 文件夾和清潔buuld –

回答

0
由於 Android的支持-V4庫的多個副本

大多數發生這種情況時在你的項目和依賴項目中。

首先嚐試刪除其他android-support-v4庫,並使其對所有庫都一樣。 如果這對你的作品,然後以其良好的其他明智按照以下步驟那會與您

1-列表項

2,打開項目構建路徑,

3,選擇「庫」標籤,

除了Android的圖書​​館

5把所有需要的JAR文件4刪除所有庫中的文件

你做完了。發生

0

這個錯誤,你可以更好地通過這個例子理解 - 如果你下載本項目環境中的任何項目意味着SDK的API級別15和這種類型的項目,你在你的工作空間,在這個時間點導入更新注意你的SDK更新API級別
19在這個時候固定的項目設置,它會在這裏建立路徑,你只需要添加外部
庫android-support-v4然後發生這個問題,由於多個副本的android-支持-V4 /如果你在項目中使用谷歌地圖圖書館的Google Play服務。

我希望如此,你會更好的理解。

Thankys