I suppose you are using Rome, be sure you have all Rome dependencies in your classpath adding the required libraries to build path.
Your code works for me so, maybe your libraries are corrupt, you can donwload it again from
http://mvnrepository.com/artifact/rome/rome/1.0
and
http://mvnrepository.com/artifact/jdom/jdom/1.0
(I recommend use maven to manage your project.)
then add the libraries to your build path again, clean your project and run it again.
You are getting a HTTP 403 error code because Google blocks the unrecognized HTTP clients, your HTTP client needs to be a recognized client like Chrome, MSIE, Gecko... etc, set the User Agent to your HTTP client and will work.
Try this code:
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import com.sun.syndication.feed.synd.SyndCategoryImpl;
import com.sun.syndication.feed.synd.SyndContentImpl;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndLinkImpl;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
public class Rome {
public static void main(String[] args) {
try {
URLConnection urlConnection = new URL("https://www.google.com/search?hl=en&q=robbery&tbm=blg&output=atom").openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
SyndFeedInput input = new SyndFeedInput();
input.setPreserveWireFeed(true);
SyndFeed feed = input.build(new XmlReader(urlConnection));
System.out.println("Feed Title: " + feed.getTitle());
for (SyndEntry entry : (List<SyndEntry>) feed.getEntries()) {
System.out.println("Title: " + entry.getTitle());
System.out.println("Unique Identifier: " + entry.getUri());
System.out.println("Updated Date: " + entry.getUpdatedDate());
for (SyndLinkImpl link : (List<SyndLinkImpl>) entry.getLinks()) {
System.out.println("Link: " + link.getHref());
}
for (SyndContentImpl content : (List<SyndContentImpl>) entry.getContents()) {
System.out.println("Content: " + content.getValue());
}
for (SyndCategoryImpl category : (List<SyndCategoryImpl>) entry.getCategories()) {
System.out.println("Category: " + category.getName());
}
}// for
}// try
catch (Exception ex) {
System.err.println(ex);
}
}
}