javafx中的RSS阅读器

时间:2011-09-20 14:37:57

标签: rss javafx-2

我正在尝试从javafx项目解析rss feed,但我得到以下异常,

显示java.lang.NullPointerException     在com.sun.webpane.webkit.network.CookieJar $ PolicyDelegateFilter.shouldAccept(CookieJar.java:42)     在com.sun.webpane.webkit.network.CookieManager.put(CookieManager.java:193)     在sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:710)     在sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)     at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049)     在java.net.URL.openStream(URL.java:1009)     在org.jugc.rss.RSSReader.readNews(RSSReader.java:38)     在org.jugc.view.RSSViewer。(RSSViewer.java:34)     在org.jugc.view.JugCMain.start(JugCMain.java:67)     在com.sun.javafx.application.LauncherImpl $ 3.run(LauncherImpl.java:127)     at com.sun.javafx.application.PlatformImpl $ 3.run(PlatformImpl.java:87)     at com.sun.javafx.application.PlatformImpl $ 2.run(PlatformImpl.java:65)     at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)     at com.sun.glass.ui.win.WinApplication.access $ 100(WinApplication.java:29)     at com.sun.glass.ui.win.WinApplication $ 1 $ 1.run(WinApplication.java:49)     在java.lang.Thread.run(Thread.java:619)

DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        URL u = new URL("http://www.jugchennai.in/feed/"); // your feed url
        System.setProperty("http.proxyHost", "192.168.32.10");
        System.setProperty("http.proxyPort", "8080");

        Document doc = builder.parse(u.openStream());
        NodeList nodes = doc.getElementsByTagName("item");
        for (int i = 0; i < nodes.getLength(); i++) {
            Element element = (Element) nodes.item(i);
            RSSFeed rSSFeed = new RSSFeed();
            rSSFeed.setTitle(getElementValue(element, "title"));
            rSSFeed.setLink(getElementValue(element, "link"));
            rSSFeed.setPublishDate(getElementValue(element, "pubDate"));
            rSSFeed.setAuthor(getElementValue(element, "dc:creator"));
            rSSFeed.setDescripition(getElementValue(element, "description"));
            rssFeeds.add(rSSFeed);
        }

我在javafx中使用以下代码

RSSReader rSSReader = RSSReader.getInstance();
    ArrayList<RSSFeed> rSSFeeds = (ArrayList) rSSReader.readNews();
    //ArrayList<RSSFeed> rSSFeeds = new ArrayList<RSSFeed>();
    RSSFeed rSSFeed1 = new RSSFeed();
    rSSFeed1.setTitle("August Meetup Scalatra, Scalate Netbeans Training");
    rSSFeed1.setLink("http://www.jugchennai.in/2011/08/13/august-meetup-scalatra-scalate-netbeans-training/");
    rSSFeeds.add(rSSFeed1);
    Hyperlink[] hpls = new Hyperlink[rSSFeeds.size()];
    for (int i = 0; i < rSSFeeds.size(); i++) {
        RSSFeed rSSFeed = rSSFeeds.get(i);
        final Hyperlink hpl = hpls[i] = new Hyperlink(rSSFeed.getTitle());

        final String url = rSSFeed.getLink();

        hpl.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent e) {
                webEngine.load(url);
            }
        });
    }
    toolBar = new VBox();
    toolBar.setVisible(true);
    toolBar.getChildren().addAll(hpls);
    getChildren().add(toolBar);
    getChildren().add(browser);

0 个答案:

没有答案