android.os.NetworkOnMainThreadException while using Android Project for RssReader

I am using the below code snippet to establish the network connection while using the android app in the main() function

URL url = new URL(urlToRssFeed);
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLReader xmlreader = parser.getXMLReader();
RssHandler theRSSHandler = new RssHandler();
InputSource is = new InputSource(url.openStream());
return theRSSHandler.getFeed();

But when creating instance of SAXParserFactory, an exception is generated as


I am not able to resolve this as i am not getting any associated stack trace of exception generation with this exception. Any idea how to resolve this ?