Android的[否类DEFF。查找错误:org.jivesoftware.smack.ConnectionConfiguration" [英] Android "No Class Deff. Find Error : org.jivesoftware.smack.ConnectionConfiguration"

查看:175
本文介绍了Android的[否类DEFF。查找错误:org.jivesoftware.smack.ConnectionConfiguration"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我运行谷歌聊天应用程序,而下面是code

Hi I am running a Google chat application, and following is the code

import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Collection;

import javax.net.ssl.SSLContext;

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.util.StringUtils;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

public class FacebookChatActivity extends Activity implements OnClickListener {

private ArrayList<String> messages = new ArrayList();
private Handler mHandler = new Handler();
private EditText mRecipient;
private EditText mSendText;
private ListView mList;
private XMPPConnection mConnection;
private String mHost, mPort, mService, mUsername, mPassword;
private ConnectionConfiguration mConnConfig;
private String TAG;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    initLayout();
     initGtalk();
 //   initFB();
//
    // Create a connection
    createConnection();

    // login
    loginToXMPP();

}

void initLayout() {
    Log.i("XMPPClient", "onCreate called");
    setContentView(R.layout.activity_facebook_chat);

    mRecipient = (EditText) this.findViewById(R.id.recipient);
    Log.i("XMPPClient", "mRecipient = " + mRecipient);
    mSendText = (EditText) this.findViewById(R.id.sendText);
    Log.i("XMPPClient", "mSendText = " + mSendText);
    mList = (ListView) this.findViewById(R.id.listMessages);
    Log.i("XMPPClient", "mList = " + mList);
    // Set a listener to send a chat text message
    Button send = (Button) this.findViewById(R.id.send);
    send.setOnClickListener(this);

    setListAdapter();
}

void initGtalk() {
    mHost = "talk.google.com";
    mPort = "5222";
    mService = "gmail";
    mUsername = "userid@gmail.com";
    mPassword = "password";
    // Set Default recipients for Gtalk
    mRecipient.setText("rameshchoudury1990@gmail.com");
}

void initFB() {
    mHost = "chat.facebook.com";
    mPort = "5222";
    mService = "xmpp";
    mUsername = "userid@chat.facebook.com";
    mPassword = "password";
    // Set Default recipients for FB
    mRecipient.setText("new_userid@chat.facebook.com");
}

void createConnection() {
    mConnConfig = new ConnectionConfiguration(mHost,
            Integer.parseInt(mPort), mService);
    mConnConfig.setSecurityMode(SecurityMode.required);
    mConnConfig.setSASLAuthenticationEnabled(true);
    mConnection = new XMPPConnection(mConnConfig);

    try {
        mConnection.connect();
        Log.i("XMPPClient",
                "[SettingsDialog] Connected to " + mConnection.getHost());
    } catch (XMPPException ex) {
        Log.e("XMPPClient", "[SettingsDialog] Failed to connect to "
                + mConnection.getHost());
        Log.e("XMPPClient", ex.toString());
        setConnection(null);
    }
}

void loginToXMPP() {
    try {
        mConnection.login(mUsername, mPassword);
        Log.i("XMPPClient", "Logged in as " + mConnection.getUser());

        // Set the status to available
        Presence presence = new Presence(Presence.Type.available);
        mConnection.sendPacket(presence);
        setConnection(mConnection);
    } catch (XMPPException ex) {
        Log.e("XMPPClient", "[SettingsDialog] Failed to log in as "
                + mUsername);
        Log.e("XMPPClient", ex.toString());
        setConnection(null);
    }
}


/* * Called by Settings dialog when a connection is established with the XMPP
 * server
 * 
 * @param connection*/

public void setConnection(XMPPConnection connection) {
    this.mConnection = 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() {
            public void processPacket(Packet packet) {
                Message message = (Message) packet;
                if (message.getBody() != null) {
                    String fromName = StringUtils.parseBareAddress(message
                            .getFrom());
                    Log.i("XMPPClient", "Got text [" + 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.multi_line_list_item, messages);
    mList.setAdapter(adapter);
}

public void onClick(View v) {
    if (v.getId() == R.id.send) {
        String to = mRecipient.getText().toString();
        String text = mSendText.getText().toString();

        Log.i("XMPPClient", "Sending text [" + text + "] to [" + to + "]");
        Message msg = new Message(to, Message.Type.chat);
        msg.setBody(text);
        mConnection.sendPacket(msg);
        messages.add(mConnection.getUser() + ":");
        messages.add(text);
        setListAdapter();
    }

}

}

当我运行这个code我正在

When I am running this code I am getting

11-26 16:20:15.283: E/dalvikvm(595): Could not find class org.jivesoftware.smack.ConnectionConfiguration', referenced from method com.example.sarojfacebookchat.FacebookChatActivity.createConnection

谁能解释一下我这个错误,如果需要的话,请给我建议的正确code。
我已经包含asmack2010.05.07.jar到我的项目

Could anyone explain me about this error and if required please suggest me the correct code. I have included asmack2010.05.07.jar into my project

推荐答案

有只有三个理由,你永远不会得到这个错误:

There are only three reasons you will ever get this error:


  1. 类真的不存在。如果您使用的是来自官方的例子code和得到这个,请确保您有库的最新版本

  2. 您还没有添加罐子构建路径。要解决此问题,右键单击Eclipse中的罐子,也构建路径►添加到构建路径。

  3. 您的罐子是不是在 /库文件夹中。这种情况发生时,你已经添加了罐子到构建路径,但ADT的新版本需要它是在 /库。把它放在那里,它重新添加到构建路径。

  1. The class genuinely doesn't exist. If you are using code from an official example and getting this, make sure you have the latest build of the library
  2. You have not added the jar to your build path. To fix this, right click on the jar in Eclipse, and do Build Path ► Add to Build Path.
  3. Your jar is not in the /libs folder. This happens when you have added the jar to the build path, but newer versions of ADT need it to be in /libs. Put it there and re-add it to the build path.

大多数情况下,出现这样的错误,因为ADT的新版本要求所有外部罐是在 /库文件夹中。你的同事可能是在一个不同的版本比你,因此错误。

Mostly, such errors occur because newer versions of the ADT require all external jars to be in the /libs folder. Your colleague was probably on a different version than you, and hence the error.

这篇关于Android的[否类DEFF。查找错误:org.jivesoftware.smack.ConnectionConfiguration&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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