2013-08-04 30 views
-1

我正在使用Java RSS解析器horrorss 我在Eclipse的Build路径中添加了horrorss-2.2.0.jar。最简单的恐怖代码无法运行

我什至不能得到最简单的代码运行。

import org.horrabin.horrorss.*; 

public class Test { 

    public static void main(String[] args) throws Exception { 

     RssParser rss = new RssParser(); 

     try{ 
       RssFeed feed = rss.load("http://rss.slashdot.org/Slashdot/slashdot"); 

       // Gets the channel information of the feed and 
       // display its title 
       RssChannelBean channel = feed.getChannel(); 
       System.out.println("Feed Title: " + channel.getTitle()); 


     }catch(Exception e){ 
       System.err.println(e); 
     } 


} 
} 

控制台输出始终是以下

Exception in thread "main" java.lang.NoClassDefFoundError: com/hp/hpl/sparta/Parser 
    at org.horrabin.horrorss.RssParser.parseFromReader(RssParser.java:431) 
    at org.horrabin.horrorss.RssParser.parseFromURL(RssParser.java:455) 
    at org.horrabin.horrorss.RssParser.load(RssParser.java:115) 
    at org.horrabin.horrorss.RssParser.load(RssParser.java:147) 
    at Test.main(Test.java:10) 
Caused by: java.lang.ClassNotFoundException: com.hp.hpl.sparta.Parser 
    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 sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    ... 5 more 

我希望你们能帮助我(或显示我要处理RSS订阅在Java中另一个不错的方法)

+0

你混淆了两件事。你的代码_does_编译。但它不_run_。第一个明显的问题:你的班级路径中是否有所有必需的罐子?似乎这个答案是否定的。 – fge

回答

3

难道你在主页上阅读过这些内容吗?

它需要Sparta-XML,一个基于XPath的轻量级XML解析器。

您需要获取Sparta-XML jar并将其添加到eclipse构建路径中。