Search code examples
javasmack

Smack API 4.0 encounter error "org/xmlpull/v1/XmlPullParserFactory" and "Cannot instantiate XMPPConnection"


I'm writing the XMpp connection to my XMpp server by Eclipse added Smack API 4.0

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;



public class XmppManager {

    public static final String HOST = "localhost";
    public static final int PORT = 5222;
    public static final String SERVICE = "chat";


    public static void main (String[] arg){
        ConnectionConfiguration connConfig = new ConnectionConfiguration(XmppManager.HOST, XmppManager.PORT,
                XmppManager.SERVICE);


    }


}

, but during on this, I encounter the error as below:

Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserFactory
    at org.jivesoftware.smack.SmackConfiguration.processConfigFile(SmackConfiguration.java:321)
    at org.jivesoftware.smack.SmackConfiguration.processConfigFile(SmackConfiguration.java:316)
    at org.jivesoftware.smack.SmackConfiguration.<clinit>(SmackConfiguration.java:148)
    at org.jivesoftware.smack.ConnectionConfiguration.<init>(ConnectionConfiguration.java:65)
    at Snapp.XmppManager.main(XmppManager.java:18)
Caused by: java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserFactory
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 5 more

Besides, adding XMPPConnection under line ""Cannot instantiate XMPPConnection""

XMPPConnection connection = new XMPPConnection (connConfig);

Java_Eclipse inform "Cannot instantiate XMPPConnection" error

Have you experienced two issues as above before ? Please help me figure out the issue.

Thanks.


Solution

  • Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserFactory

    You need to have XPP3 in your classpath.

    Besides, adding XMPPConnection under line ""Cannot instantiate XMPPConnection""

    Use XMPPTCPConnection instead of XMPPConnection in Smack 4.