I am writing an app to pull and display content from an atom feed. The method for that works, but I get the error "Unhandled exception: java.lang.Exception
" when I try to call the method "showFeed()
" in onNavigationItemSelected
.
package com.myapp;
import java.net.URL;
import java.util.Iterator;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
// ...
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
showFeed();
}
}
// ...
public void showFeed() throws Exception {
URL url = new URL("http://feeds.feedburner.com/javatipsfeed");
XmlReader xmlReader = null;
try {
xmlReader = new XmlReader(url);
SyndFeed feeder = new SyndFeedInput().build(xmlReader);
System.out.println("Title Value " + feeder.getAuthor());
for (Iterator iterator = feeder.getEntries().iterator(); iterator.hasNext();) {
SyndEntry syndEntry = (SyndEntry) iterator.next();
System.out.println(syndEntry.getTitle());
}
} finally {
if (xmlReader != null)
xmlReader.close();
}
}
I want to call this method in onNavigationItemSelected
.