RSS Reader in javafx
I'm trying parse a rss feed from javafx project, but i'm getting the following exception,
java.lang.NullPointerException at com.sun.webpane.webkit.network.CookieJar$PolicyDelegateFilter.shouldAccept(CookieJar.java:42) at com.sun.webpane.webkit.network.CookieManager.put(CookieManager.java:193) at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:710) at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049) at java.net.URL.openStream(URL.java:1009) at org.jugc.rss.RSSReader.readNews(RSSReader.java:38) at org.jugc.view.RSSViewer.(RSSViewer.java:34) at org.jugc.view.JugCMain.start(JugCMain.java:67) at 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.j开发者_如何转开发ava:29) at com.sun.glass.ui.win.WinApplication$1$1.run(WinApplication.java:49) at 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);
}
I'm using following code in 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);
精彩评论