编程语言
首页 > 编程语言> > java-Smack API 4.0遇到错误“ org / xmlpull / v1 / XmlPullParserFactory”和“无法实例化XMPPConnection”

java-Smack API 4.0遇到错误“ org / xmlpull / v1 / XmlPullParserFactory”和“无法实例化XMPPConnection”

作者:互联网

我正在通过Eclipse添加的Smack API 4.0将XMpp连接写入我的XMpp服务器

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


    }


}

,但在此过程中,我遇到如下错误:

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

此外,在“无法实例化XMPPConnection”行下添加XMPPConnection

XMPPConnection connection = new XMPPConnection (connConfig);

Java_Eclipse通知“无法实例化XMPPConnection”错误

您是否遇到过上述两个问题?请帮助我找出问题所在.

谢谢.

解决方法:

Exception in thread “main” java.lang.NoClassDefFoundError:
org/xmlpull/v1/XmlPullParserFactory

您的类路径中必须有XPP3.

Besides, adding XMPPConnection under line “”Cannot instantiate
XMPPConnection””

在Smack 4中使用XMPPTCPConnection代替XMPPConnection.

标签:smack,java
来源: https://codeday.me/bug/20191121/2053313.html