如何清除机器人在XMPP聊天程序错误 [英] How to clear errors in xmpp chat program in android

查看:140
本文介绍了如何清除机器人在XMPP聊天程序错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用XMPP聊天应用。我的问题是,当运行出现一个对话框,显示你的项目中包含然后错误修复和运行的项目,但没有项目资源管理器中显示错误,警告标志是显示(希望这不会影响rnuning项目)。控制台页面显示如下:

  [2013年9月25日10时25分01秒 - 地塞米松装载机]无法执行DEX:多DEX文件定义LCOM /基奈/ jbosh / AbstractAttr;
[2013年9月25日10时25分01秒 - XMPPChatDemo]转换为Dalvik的格式失败:无法执行DEX:多DEX文件定义LCOM /基奈/ jbosh / AbstractAttr;

和我的程序code是:

 公共类XMPPChatDemoActivity延伸活动{    公共静态最后弦乐HOST =192.168.1.4;
    公共静态最终诠释PORT = 5222;
    公共静态最后弦乐USERNAME =semyma;
    公共静态最后的字符串密码=电脑;
    私人XMPPConnection连接;
    私人的ArrayList<串GT;消息=新的ArrayList<串GT;();
    私人处理程序mHandler =新的处理程序();
    私人的EditText收件人;
    私人的EditText文字信息;
    私人的ListView列表视图;
    / **当第一次创建活动调用。 * /
    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        收件人=(EditText上)this.findViewById(R.id.toET);
        文字信息=(EditText上)this.findViewById(R.id.chatET);
        列表视图=(ListView控件)this.findViewById(R.id.listMessages);
        setListAdapter();
        //设置监听器发送聊天短信
        按钮发送=(按钮)this.findViewById(R.id.sendBtn);
        send.setOnClickListener(新View.OnClickListener(){
            公共无效的onClick(查看视图){
                。字符串= recipient.getText()的toString();
                字符串文本= textMessage.getText()的toString()。
                Log.i(XMPPChatDemoActivity,发送文本+文字+到+到);
                消息味精=新消息(于Message.Type.chat);
                msg.setBody(文本);
                如果(连接!= NULL){
                    connection.sendPacket(MSG);
                    messages.add(connection.getUser()+:);
                    messages.add(文本);
                    setListAdapter();
                }
            }
        });        连接();
    }    / **
     *通过设置对话框时调用连接与XMPP establised
     *服务器
     *
     * @参数连接
     * /
    公共无效setConnection(XMPPConnection连接){
        this.connection =连接;
        如果(连接!= NULL){
            //添加一个数据包监听器来获取消息发送给我们
            PacketFilter过滤器=新MessageTypeFilter(Message.Type.chat);
            connection.addPacketListener(新PacketListener(){
                @覆盖
                公共无效processPacket(分组数据包){
                    消息消息=(消息)数据包;
                    如果(message.getBody()!= NULL){
                        字符串FROMNAME = StringUtils.parseBareAddress(消息
                                。从获得());
                        Log.i(XMPPChatDemoActivity,文本收到+ message.getBody()
                                +由+ FROMNAME);
                        messages.add(FROMNAME +:);
                        messages.add(message.getBody());
                        //传入的消息添加到列表视图
                        mHandler.post(新的Runnable(){
                            公共无效的run(){
                                setListAdapter();
                            }
                        });
                    }
                }
            },过滤器);
        }
    }    私人无效setListAdapter(){
        ArrayAdapter<串GT;适配器=新ArrayAdapter<串GT;(这一点,
                R.layout.listitem,消息);
        listview.setAdapter(适配器);
    }    @覆盖
    保护无效的onDestroy(){
        super.onDestroy();
        尝试{
            如果(连接!= NULL)
                connection.disconnect();
        }赶上(例外五){        }
    }    公共无效连接(){        最后ProgressDialog对话框= ProgressDialog.show(这一点,
                连接...,请稍候...,假);        线程t =新主题(新的Runnable(){            @覆盖
            公共无效的run(){
                //创建一个连接
                ConnectionConfiguration connConfig =新ConnectionConfiguration(
                        主机,端口);
                XMPPConnection连接=新XMPPConnection(connConfig);
                尝试{
                    connection.connect();
                    Log.i(XMPPChatDemoActivity
                            连接到+ connection.getHost());
                }赶上(XMPPException前){
                    Log.e(XMPPChatDemoActivity,无法连接到
                            + connection.getHost());
                    Log.e(XMPPChatDemoActivity,ex.toString());
                    setConnection(NULL);
                }
                尝试{
                    // SASLAuthentication.supportSASLMechanism(普通,0);
                    connection.login(用户名,密码);
                    Log.i(XMPPChatDemoActivity
                            登录身份是+ connection.getUser());
                    //将状态设置为可用
                    presence presence =新的presence(presence.Type.available);
                    connection.sendPacket(presence);
                    setConnection(连接);
                    名册名册= connection.getRoster();
                    收集和LT; RosterEntry>条目= roster.getEntries();
                    对于(RosterEntry项:项){
                        Log.d(XMPPChatDemoActivity
                                --------------------------------------);
                        Log.d(XMPPChatDemoActivity,RosterEntry+条目);
                        Log.d(XMPPChatDemoActivity
                                用户:+ entry.getUser());
                        Log.d(XMPPChatDemoActivity
                                名称:+ entry.getName());
                        Log.d(XMPPChatDemoActivity
                                状态:+ entry.getStatus());
                        Log.d(XMPPChatDemoActivity
                                类型:+ entry.getType());
                        presence入门presence = roster.get presence(入门
                                .getUser());
                        Log.d(XMPPChatDemoActivity,presence状态:
                                +入门presence.getStatus());
                        Log.d(XMPPChatDemoActivity,presence类型:
                                +入门presence.getType());
                        presence.Type型=条目presence.getType();
                        如果(类型== presence.Type.available)
                            Log.d(XMPPChatDemoActivity,presence可用的编缉);
                        Log.d(XMPPChatDemoActivity,presence:
                                +入门presence);                    }
                }赶上(XMPPException前){
                    Log.e(XMPPChatDemoActivity,无法登录为
                            + USERNAME);
                    Log.e(XMPPChatDemoActivity,ex.toString());
                    setConnection(NULL);
                }                dialog.dismiss();
            }
        });
        t.start();
        dialog.show();
    }
}


解决方案

出现此错误,你会更好地这个例子中明白 - 如果你下载这个项目环境中的任何项目意味着SDK的API级别15和这种类型的项目更新你在你的工作空间,在这个时间点要注意你的SDK API等级结果导入更新
19,此时固定项目设置,它会去在这个构建路径时,只需添加外置结果
库Android的支持-V4那么这个问题的发生是由于Android的支持-V4的/如果你在项目中使用谷歌地图图书馆的Google Play服务。

的多个副本

我希望这样你会更明白。

Thankys

Hi I am creating a chat application using xmpp. My problem is that while running the project a dialog box appears showing 'your project contain errors fix then and run', but there is no errors shown in project explorer, a warning is sign is shown(hope it doesn't effect rnuning a project). The console page is showing like this :

[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;  

And my program code is :

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();
    }
}

解决方案

This error occurs you will better understand by this example - In case you download any project in this project environment means SDK updated in API LEVEL 15 and such type of project you import in your work-space and at this time point to be noted your SDK updated in API LEVEL
19 at this time fixed project setup and it will goes Build Path at this you just add external
libraries android-support-v4 then this problem has occurs due to the multiple copies of android-support-v4/google-play-services if you use Google map libraries in your project.

i hope so you will better understand.

Thankys

这篇关于如何清除机器人在XMPP聊天程序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆