带有 aSmack 库的 XMPP 出现错误?
Posted
技术标签:
【中文标题】带有 aSmack 库的 XMPP 出现错误?【英文标题】:XMPP with aSmack library getting error? 【发布时间】:2012-06-13 12:05:12 【问题描述】:我正在尝试让 aSmack 在我的项目中工作。在 Eclipse 中创建了一个标准项目,将 jars(smack.jar、smackx-debug.jar、smackx-jingle.jar、smackx.jar)添加到 libs 文件夹。开始使用 XMPP 类,但我不确定我是否应该做其他事情来正确设置项目(稍后),因为它不起作用。当我运行应用程序时,我收到此错误Could not find class 'java.beans.PropertyDescriptor', referenced from method org.jivesoftware.smack.util.PacketParserUtils.parseWithIntrospection
,当我尝试发送消息时,我收到此错误java.lang.IllegalStateException: Not connected to server.
和at org.jivesoftware.smack.XMPPConnection.sendPacket(XMPPConnection.java:445)
这是我正在使用的代码
public class ClientJabberActivity extends Activity
private final static String server_host = "aaaaa.com" ;
private final static int SERVER_PORT = 5222 ;
private final static String SERVICE_NAME = "gmail.com" ;
private final static String LOGIN = "xxxx@name.com" ;
private final static String PASSWORD = "yyyy";
ArrayList<String> m_discussionThread;
ArrayAdapter<String> m_discussionThreadAdapter;
XMPPConnection m_connection;
private Handler m_handler;
@ Override
public void onCreate (Bundle savedInstanceState)
super . onCreate (savedInstanceState);
setContentView (R.layout.main);
m_handler = new Handler ();
try
initConnection ();
catch (XMPPException e)
e. printStackTrace ();
final EditText recipient = (EditText) this . findViewById (R.id.recipient);
final EditText message = (EditText) this . findViewById (R.id.message);
ListView list = (ListView) this . findViewById (R.id.thread);
m_discussionThread = new ArrayList<String>();
m_discussionThreadAdapter = new ArrayAdapter<String> ( this ,
R.layout.multi_line_list_item, m_discussionThread);
list.setAdapter(m_discussionThreadAdapter);
Button send = (Button) this . findViewById (R.id.send);
send. setOnClickListener ( new View. OnClickListener ()
public void onClick (View view)
String to = recipient.getText().toString ();
String text = message.getText().toString ();
Message msg = new Message(to, Message.Type.chat);
msg.setBody(text);
m_connection.sendPacket (msg);
m_discussionThread. add ( " Me : " );
m_discussionThread. add (text);
m_discussionThreadAdapter. notifyDataSetChanged ();
);
private void initConnection () throws XMPPException
ConnectionConfiguration config = new ConnectionConfiguration (server_host, SERVER_PORT, SERVICE_NAME);
m_connection = new XMPPConnection (config);
m_connection.connect ();
m_connection.login(LOGIN, PASSWORD);
Presence presence = new Presence(Presence.Type.available);
Log.i("ID", ""+presence);
m_connection.sendPacket (presence);
PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
m_connection.addPacketListener(new PacketListener()
public void processPacket(Packet packet)
Message message = (Message) packet;
if (message.getBody() != null)
String fromName = StringUtils.parseBareAddress(message.getFrom());
m_discussionThread.add(fromName + ":");
m_discussionThread.add(message.getBody());
m_handler.post(new Runnable()
public void run()
m_discussionThreadAdapter.notifyDataSetChanged();
);
, filter);
ChatManager chatmanager = m_connection.getChatManager();
chatmanager.addChatListener(new ChatManagerListener()
public void chatCreated(final Chat chat, final boolean createdLocally)
chat.addMessageListener(new MessageListener()
public void processMessage(Chat chat, Message message)
System.out.println("Received message: "
+ (message != null ? message.getBody() : "NULL"));
Log.i("CHAT USER", "Received message is: "+message.getBody());
);
);
有人在您的 XMPP 客户端中遇到过这个问题。是 jar 文件中的问题还是我必须更改代码中的任何内容...
【问题讨论】:
【参考方案1】:您确定您使用的是 asmack 罐子而不是 smack 罐子吗?因为如果你使用普通的 smack,这个错误看起来会出现。
【讨论】:
正如 Steffen 所说,您似乎使用了错误的罐子。使用这个 jar code.google.com/p/gtalksms/source/browse/libs/… 它通常是最新的。 是的,我在 jar 文件中犯了一个错误,现在它适用于 gmail 帐户,但不适用于我的服务器帐户,这将是什么问题.... 好。关于你的问题。您必须更清楚地解释现在的问题。 @Jug6ernaut 您的链接已损坏,您能提出一些替代方案吗?还是将 jar 上传到 Dropbox 并分享?以上是关于带有 aSmack 库的 XMPP 出现错误?的主要内容,如果未能解决你的问题,请参考以下文章