我在使用 smack 4.2 Openfire 创建 XMPP 客户端时遇到问题

I'm having trouble creating XMPP client using smack 4.2 Openfire

我想创建一个连接到我的 Openfire 服务器的简单 XMPP 客户端。当我 运行 代码时,我遇到了以下问题。

代码:

public void setConnection() {

    try {

        XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
        config.setUsernameAndPassword(userName,password);
        config.setResource("temp");
        config.setXmppDomain("undercrroft");

        AbstractXMPPConnection connection = new XMPPTCPConnection(config.build());
        connection.connect();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (SmackException e) {
        e.printStackTrace();
    } catch (XMPPException e) {
        e.printStackTrace();
    }

错误:

Information:java: Errors occurred while compiling module 'Messenger'
Information:javac 1.8.0_121 was used to compile java sources
Information:16/4/17 1:52 AM - Compilation completed with 2 errors and 0 warnings in 871ms
/home/paradox/Desktop/Project/Messenger/src/ConnectServer.java
Error:(28, 19) java: cannot access org.jxmpp.stringprep.XmppStringprepException
                class file for org.jxmpp.stringprep.XmppStringprepException not found
Error:(29, 19) java: cannot access org.jxmpp.jid.DomainBareJid
                class file for org.jxmpp.jid.DomainBareJid not found

这些是我的进口商品:

import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;

谢谢。

您缺少所需的 jxmpp 库。请查看 Smack 文档,其中列出了所有依赖项:https://github.com/igniterealtime/Smack/wiki/Smack-4.2-Readme-and-Upgrade-Guide#using-eclipses-android-development-tools-adt-ant-based-build

请注意,强烈建议使用依赖管理器(Gradle、Maven、Ivy)来防止此类问题。

更新库..!

这两个库是在较新的库中定义的。