简体   繁体   中英

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

I want to create a simple XMPP client that connects to my Openfire server. I got the following problem when I'm running the code.

code:

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

Error:

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

These are my imports:

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;

Thanks.

You are missing the required jxmpp libraries. Please have a look at the Smack documentation, which lists all dependencies: https://github.com/igniterealtime/Smack/wiki/Smack-4.2-Readme-and-Upgrade-Guide#using-eclipses-android-development-tools-adt-ant-based-build

Note that using a dependency manager (Gradle, Maven, Ivy) is highly recommended to prevent issues like this.

Update the Library..!

Those two libraries are defined in the newer library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM