首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Smack抛出"java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserFactory:“

Smack抛出"java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserFactory:“
EN

Stack Overflow用户
提问于 2014-06-13 09:57:50
回答 1查看 13.4K关注 0票数 7

所以我使用Smack为英雄联盟运行我的聊天机器人,但是我甚至不能让机器人出现,因为我似乎找不到一个缺失的类错误。下面的代码和错误,谢谢你的帮助,-Nick

另外:是的,这段代码取自一个例子,因为当我自己尝试它的时候,我仍然得到相同的错误。

代码语言:javascript
复制
package com.nickparks.bot;

import java.util.*;
import java.io.*;

import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;

public class JabberSmackAPI implements MessageListener{

    XMPPConnection connection;

    public void login(String userName, String password) throws XMPPException
    {
        ConnectionConfiguration config = new ConnectionConfiguration("chat.na1.lol.riotgames.com",5223);
        connection = new XMPPTCPConnection(config);

        try {
            connection.connect();
            connection.login(userName, password, "xiff");
        } catch (SmackException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void displayBuddyList()
    {
        Roster roster = connection.getRoster();
        Collection<RosterEntry> entries = roster.getEntries();

        System.out.println("\n\n" + entries.size() + " buddy(ies):");
        for(RosterEntry r:entries)
        {
            System.out.println(r.getUser());
        }
    }

    public void disconnect()
    {
        try {
            connection.disconnect();
        } catch (SmackException.NotConnectedException e) {
            e.printStackTrace();
        }
    }

    public void processMessage(Chat chat, Message message)
    {
        if(message.getType() == Message.Type.chat)
            System.out.println(chat.getParticipant() + " says: " + message.getBody());
    }

    public static void main(String args[]) throws XMPPException, IOException
    {
        // declare variables
        JabberSmackAPI c = new JabberSmackAPI();





        // Enter your login information here
        c.login("bot", "Password");

        c.displayBuddyList();

        System.out.println("-----");

        System.out.println("Who do you want to talk to? - Type contacts full email address:");
        String talkTo = br.readLine();

        System.out.println("-----");
        System.out.println("All messages will be sent to " + talkTo);
        System.out.println("Enter your message in the console:");
        System.out.println("-----\n");

        while( !(msg=br.readLine()).equals("bye"))
        {
            System.out.println("test");
        }

        c.disconnect();
        System.exit(0);
    }

}

下面是我得到的错误:

代码语言:javascript
复制
Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserFactory at org.jivesoftware.smack.SmackConfiguration.processConfigFile(SmackConfiguration.java:321)
atorg.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 com.nickparks.bot.JabberSmackAPI.login(JabberSmackAPI.java:16)
at com.nickparks.bot.JabberSmackAPI.main(JabberSmackAPI.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 11 more
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-14 17:29:37

您的类路径中需要有XPP3 (XML Pull Parser 3)。Smack 4不再捆绑它(不像Smack 3)。

我还推荐使用具有依赖关系解析的构建系统,如maven或gradle,它们将自动获取所需的依赖关系。

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24196588

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档